在使用 DHTML、AJAX 等的网站上使用 Python mechanize?
所以,假设我正在尝试创建一些内容来回复 twitter 上某个“标签关键字”的推文(例如“#FirstWorldProblems”),我有一个如下所示的脚本:
# apply settings, create a mechanize.Browser, etc.
login() # log into twitter
# at this point we've logged into twitter, now, we will perform navigate to their search page and run a search query:
br.open('http://twitter.com/search?q=' + hashtag)
print(br.response().read()) # print the response
所以,我上面的内容有点像一个简短的版本,可以快速到达给我带来麻烦的地方。
我设置了浏览器,登录推特,一切都完成了,没有问题。但是,然后我搜索主题标签(使用 br.open),然后打印响应。
在 Twitter 上,只有当您将鼠标悬停在特定链接上并指向“#”时,才会出现“回复”链接(因为它会打开一个小弹出窗口,您可以在其中输入回复),我该如何点击“回复”链接,因为它没有显示在响应中?
So, let's say I'm trying to create something that replies to tweets of a certain "hashtag keyword" on twitter (for example "#FirstWorldProblems") I have a script that looks like this:
# apply settings, create a mechanize.Browser, etc.
login() # log into twitter
# at this point we've logged into twitter, now, we will perform navigate to their search page and run a search query:
br.open('http://twitter.com/search?q=' + hashtag)
print(br.response().read()) # print the response
So, what I have above is sort of an abbreviated version to quickly get to the spot giving me trouble.
I set up a browser, log into twitter, all done no problemo. But, then I run a search for the hashtag (using br.open) and then I print the response.
On Twitter, the "Reply" link only appears when you hover over a specific link and leads to "#" (because it opens a little pop-up thing where you can enter your reply), how would I click on the "Reply" link, because it doesn't show up in the response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的问题实际上只是访问 Twitter,那么 dmedvinsky 可能是对的。
然而,如果你真的希望能够抓取网站(同时允许他们的 javascript 像平常一样运行......),你可能会想要更强大的东西。
虽然它有很多包袱,但我强烈建议您使用 Qt、PySide 并熟悉 QWebKit。您可以从 Python 驱动一个“真正的”网络浏览器,并获得人们所期望的所有好处(和问题)。但是,到目前为止,这是我发现的最好、最干净的方法来完成你所询问的事情。
If your problem is actually just accessing Twitter, dmedvinsky is probably right.
However, if you really want to be able to scrape websites (while allowing their javascript to run as it normally would..) you'll probably want something a bit more robust.
While it's a lot of baggage, I strongly urge you to grab Qt, PySide, and get familiar with QWebKit. You can drive a 'real' web browser from Python and get all the benefits (and problems;) one would expect. But, so far it's the best and cleanest method I've found to do what you're asking about.