这是可能加载JavaScript执行后使用python的页面? [英] Is this possible to load the page after the javascript execute using python?

查看:260
本文介绍了这是可能加载JavaScript执行后使用python的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是页面我读

<html>
<head>
<script type="text/javascript">
    document.write("Hello World")
</script>
</head>
<body>
</body>
</html>

正如你所看到的,的Hello World 是在HTML页面上使用javascript补充说,当我使用HTML解析器,像 BeautifulSoup 解析它,它不能解析的Hello World ,可以给我解析在客户端如何真正看到实际结果.. ..?谢谢你。

As you can see, the Hello World is added on the HTML page using javascript, when I use the HTML parser, like the BeautifulSoup to parse it, it can't parse the Hello World, it is possible to me parse the actually result on how the client side really see....? Thanks.

推荐答案

在Python编写web刮刀,当我遇到了类似的问题,我发现的与BeautifulSoup非常有用的组合硒网络驱动程序。在code最终看起来是这样的:

I ran into a similar problem when writing web scrapers in python, and I found Selenium Web Driver in combination with BeautifulSoup very useful. The code ends up looking something like this:

browser = WebDriver.Firefox()
browser.get("http://www.yoursite.com")
soup = BeautifulSoup(browser.page_source)
...

使用webdriver的硒,有功能上也为等到一定的DOM元素已加载,这使得与JavaScript元素的时机更容易了。

With Selenium WebDriver, there's also functionally for a "wait until a certain DOM element has loaded", which makes the timing with javascript elements easier too.

这篇关于这是可能加载JavaScript执行后使用python的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆