BeautifulSoup获取innerhtml数据

发布于 2024-09-08 07:22:59 字数 134 浏览 2 评论 0 原文

我正在尝试从网站读取数据。我可以看到我需要的值,但该值没有出现在下载的 html 代码中(使用 urllib2)。该值由某个 js 文件创建,并作为该 id 的 innerhtml 嵌入到网页中。 PS:如何提取?与浏览器不同,原始源代码无法渲染 js!

I am trying to read data from a website. I can see the value I need but the value does not appear in the downloaded html code (using urllib2). The value is created by some js file and embedded into the webpage as innerhtml for that id.
PS: How can that be extracted? raw source code cannot render js unlike the browsers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

内心激荡 2024-09-15 07:22:59

获取数据的另一种方法是让浏览器使用 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

坏尐絯 2024-09-15 07:22:59

您有两个选择:让浏览器保存 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文