BeautifulSoup获取innerhtml数据
我正在尝试从网站读取数据。我可以看到我需要的值,但该值没有出现在下载的 html 代码中(使用 urllib2)。该值由某个 js 文件创建,并作为该 id 的 innerhtml 嵌入到网页中。 PS:如何提取?与浏览器不同,原始源代码无法渲染 js!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取数据的另一种方法是让浏览器使用 Selenium 执行所有操作并读取渲染的 html。有点慢但肯定有效。
您可以在这里找到通过 Python 使用 Selenium 的入门指南:
http://jimmyg.org/blog/2009/开始使用-selenium-and-python.html
Another way of getting data is leaving the browser do all the stuff using Selenium and read the rendered html. A bit slow but surely effective.
Here you can find a getting started guide for using Selenium with Python:
http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html
您有两个选择:让浏览器保存 DOM(这包括脚本所做的所有更改)或使用 JavaScript 引擎执行嵌入的脚本。
对于后一种方法,请尝试使用基于 Java 的引擎,例如 Rhino 并使用 env.js。
You have two options: Have the browser save the DOM (this includes all changes made by scripts) or use a JavaScript engine to execute the embedded scripts.
For the latter route, try a Java based engine like Rhino and emulate the browser with env.js.