单击 python 中的 javascript 链接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5207948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:22:30  来源:igfitidea点击:

Click on a javascript link within python?

javascriptpythonscreen-scrapingmechanizespidermonkey

提问by Lostsoul

I am navigating a site using python's mechanize module and having trouble clicking on a javascript link for next page. I did a bit of reading and people suggested I need python-spidermonkey and DOMforms. I managed to get them installed by I am not sure of the syntax to actually click on the link.

我正在使用 python 的 mechanize 模块导航一个站点,但在单击下一页的 javascript 链接时遇到问题。我做了一些阅读,人们建议我需要 python-spidermonkey 和 DOMforms。我设法通过我不确定实际单击链接的语法来安装它们。

I can identify the code on the page as:

我可以将页面上的代码识别为:

<a href="javascript:__doPostBack('ctl00$MainContent$gvSearchResults','Page')">2</a>

Does anyone know how to click on it? or if perhaps there's another tool.

有人知道怎么点击吗?或者也许还有其他工具。

Thanks

谢谢

采纳答案by sw.

I mainly use HtmlUnitunder jython for these use cases. Also I published a simple article on the subject: Web Scraping Ajax and Javascript sites.

对于这些用例,我主要使用jython 下的HtmlUnit。我还发表了一篇关于该主题的简单文章:Web Scraping Ajax 和 Javascript 站点

回答by hoju

instead of struggling with python-spidermonkey try webkit's qt python bindings.

与其在 python-spidermonkey 上挣扎,不如试试webkit 的 qt python bindings

Here is a full example to execute JavaScript and extract the final HTML.

这是执行 JavaScript 并提取最终 HTML完整示例

回答by n00b

how about calling __doPostBack('ctl00$MainContent$gvSearchResults','Page$'+pageid);(javascript method, via python-spidermonkey)

如何调用__doPostBack('ctl00$MainContent$gvSearchResults','Page$'+pageid);(javascript 方法,通过 python-spidermonkey)