用selenium+pyquery爬取javascript生成的页面内容

作者在 2015-03-08 20:36:03 发布以下内容
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from pyquery import PyQuery as pq
from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.baidu.com/')

html = browser.find_element_by_xpath("//*").get_attribute("outerHTML")  # 不要用 browser.page_source,那样得到的页面源码不标准
browser.quit()

html = pq(html)
html.find("script").remove()    # 清理 <script>...</script>
html.find("style").remove()     # 清理 <style>...</style>

print html.outer_html()

Python | 阅读 8879 次
文章评论,共0条
游客请输入验证码
浏览2799463次
文章归档