Python 爬取网页中JavaScript动态添加的内容(二)

使用 selenium + phantomjs 实现

1、准备环境

selenium(一个用于web应用程测试的工具)安装:pip install selenium
phantomjs(是一种无界面的浏览器,用于完成网页的渲染)下载:http://phantomjs.org/download.html

2、使用

from selenium import webdriver

url = 'http://jandan.net/ooxx'
driver = webdriver.PhantomJS(
    executable_path='D:/Software/phantomjs-2.1.1-windows/bin/phantomjs.exe')  # 如果没有配置phantomjs的环境变量,需要手动指定路径
driver.get(url)
print(driver.page_source)

猜你喜欢

转载自blog.csdn.net/qq_40925239/article/details/82890301