捐助郴维网
感谢您对郴维网的支持,你的支持将是郴维网持续发展的动力!
二维码
×
当前位置:郴维网 > 原创文章 > 正文
3 2018.05

Selenium+PhantomJS提示:Selenium support for PhantomJS has been deprecated

点击次数:3206 更新时间:2018/5/3 21:32:23  【打印此页

新安装的Python环境,调试基于Selenium+PhantomJS的动态爬虫程序,报了这么个错误:

C:\Python\Python36-32\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py:49: 
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless 
versions of Chrome or Firefox instead  warnings.warn('Selenium support for PhantomJS has 
been deprecated, please useheadless '

这个意思是说,新版本的Selenium不再支持PhantomJS了,请使用Chrome或Firefox的无头版本来替代。


这提供2种解决方案


一:降级selenium使用
pip uninstall selenium #先卸载selenium 
pip install selenium==3.4.3 #指定版本安装selenium

防止以后官网没得下载,先备份个selenium3.4.3和PhantomJS 下载地址

 


二:使用Headless Chrome和Headless Firefox
使用Headless Chrome
Headless模式是Chrome 59中的新特征。
要使用Chrome需要安装 chromedriver。
chromedriver驱动大全
http://chromedriver.storage.googleapis.com/index.html

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
br = webdriver.Chrome(chrome_options=chrome_options)
br.get('https://www.baidu.com/')
baidu = br.find_element_by_id('su').get_attribute('value')
print(baidu)

 

使用Headless Firefox
要使用Firebox需要安装 geckodriver。
geckodriver.exe驱动大全
https://github.com/mozilla/geckodriver/releases

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument('--headless')
br = webdriver.Firefox(firefox_options=firefox_options)
br.get('https://www.baidu.com/')
baidu = br.find_element_by_id('su').get_attribute('value')
print(baidu)
提示
郴维网为您提供各类专业服务:
软件开发,电脑配件销售,WIFI路由器销售,上门电脑维修,上门安装系统,系统安装,软、硬件安装,电脑除尘清灰,显示器维修,WIFI安装调试,服务器维护,数据恢复,密码破解,网络布线,网络检修,打印机维修,打印机加碳粉,苹果电脑安装系统,苹果电脑安装双系统,监控安装维护,电脑外包,笔记本电脑维修,餐饮、美容行业软件安装 等。。。。。。
点击次数:3206 更新时间:2018/5/3 21:32:23  【打印此页
关键词推荐:郴州电脑城 郴州电脑维修公司 维修电脑公司 郴州软件开发 上门电脑维修 上门安装系统 笔记本电脑维修 郴州打印机维修 打印机加碳粉 电脑安装双系统 苹果电脑双系统 液晶显示器维修 联想笔记本维修 联想笔记本维修电话 戴尔笔记本维修电话 郴州戴尔笔记本维修 戴尔笔记本郴州维修点 华硕笔记本维修点 郴州华硕笔记本维修 郴州笔记本上网维修