【发布时间】:2011-09-15 21:03:54
【问题描述】:
我正在尝试使用几乎完全是 Javascript 的 Selenium(在 Python 中)抓取网页。
例如,这是页面的正文:
<body class="bodyLoading">
<!-- this is required for GWT history support -->
<iframe id="__gwt_historyFrame" role="presentation" width="0" height="0" tabindex="-1" title="empty" style="position:absolute;width:0;height:0;border:0" src="javascript:''"> </iframe>
<!-- For printing window contents -->
<iframe id="__printingFrame" role="presentation" width="0" height="0" tabindex="-1" title="empty" style="width:0;height:0;border:0;" />
<!-- TODO : RECOMMENDED if your web app will not function without JavaScript enabled -->
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled in order for
Regulations.gov to display correctly.
</div>
</noscript>
</body>
由于某种原因,selenium(使用 Firefox 引擎)不会评估此页面上的 javascript。如果我使用 get_html_source 函数,它只会返回上面的 html,而不是我可以在浏览器(和 Selenium 浏览器)中看到的 JavaScript 导入的 HTML。而且,不幸的是,我无法从 iFrame 中找出 src 属性,只是说 javascript: 我无法弄清楚。
关于如何确保 Selenium 处理这个 iFrame 有什么想法吗?
【问题讨论】:
-
您能否发布您的 selenium 驱动程序代码 - 例如,您是否允许有足够的时间来加载页面(selenium 是异步的等等)