Selenium+PhantomJS使用时报错原因及解决方案
问题
今天在使用selenium
+PhantomJS
动态抓取网页时,出现如下报错信息:
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 use headless '
翻译过来就是:
selenium已经放弃PhantomJS,了,建议使用火狐或者谷歌无界面浏览器。
解决方案
selenium版本降级
通过pip show selenium
显示,默认安装版本为3.8.1
。
将其卸载pip uninstall selenium
,重新安装并指定版本号pip install selenium==2.48.0
。
再次运行,发现没有报错,搞定!
使用无界面浏览器
Selenium+Headless Firefox
Selenium+Headless Firefox
和Selenium+Firefox
,区别就是实例option
的时候设置-headless
参数。
前提条件:
- 本地安装Firefox浏览器
- 本地需要geckodriver驱动器文件,如果不配置环境变量的话,需要手动指定executable_path
参数。
示例代码:
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
def main():
options = Options()
options.add_argument('-headless')
driver = Firefox(executable_path='./geckodriver', firefox_options=options)
driver.get("https://www.qiushibaike.com/8hr/page/1/")
print(driver.page_source)
driver.close()
if __name__ == '__main__':
main()
Selenium+Headless Chrome
与Firefox
类似,双手奉上。
前提条件:
- 本地安装Chrome浏览器
- 本地需要chromedriver驱动器文件,如果不配置环境变量的话,需要手动指定executable_path
参数。
示例:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def main():
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=chrome_options)
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.close()
if __name__ == '__main__':
main()
本文转自:csdn的https://blog.csdn.net/u010358168/article/details/79749149
如上,完美解决~
Selenium+PhantomJS使用时报错原因及解决方案的更多相关文章
- Selenium+PhantomJS使用时报错原因及解决方案(转)
Selenium+PhantomJS使用时报错原因及解决方案 问题 今天在使用selenium+PhantomJS动态抓取网页时,出现如下报错信息: UserWarning: Selenium ...
- Selenium+PhantomJS使用时报错原因
运行下面代码:'''PhantomJS运用''' from selenium import webdriverimport time # 通过keys模拟键盘from selenium.webdriv ...
- 分析https网页加载http资源导致的页面报错原因及其解决方案
https网页加载http资源导致的页面报错及解决方案 https是当下的网站的主流趋势,甚至像苹果这样的大公司,则完全要求用户必须使用https地址. 然而对于以前http链接来说,我们往往就存在一 ...
- angularJS中$http.get( ).success( )报错原因及解决方案
一.问题描述: 电脑安装的angular1.6.7版本,项目中使用了$http.get( ).success( ),控制台报错: $http.get(...).success is not a fun ...
- ie7,8下__flash__addCallback报错原因及解决方案
首先附张图,以直观说明错误的现象:(ie7.8)
- C# ODP.NET 调用Oracle函数返回值时报错的一个解决方案
有人在社区问到:C#调用Oracle中自定义函数的返回值时,无法正常调用.但在PL/SQL中正常调用返回. 于是动手一试: 1.准备函数(Oralce 11g.2.0.0.4) CREATE OR R ...
- Selenium chromeDriver启动时报错:session not created: This version of ChromeDriver only supports Chrome
解决方案: 这是因为ChromeDriver与本地chrome浏览器的版本不一致导致 ChromeDriver下载地址:http://npm.taobao.org/mirrors/chromedriv ...
- python中用selenium调Firefox报错问题
python在用selenium调Firefox时报错: Traceback (most recent call last): File "G:\python_work\chapter11 ...
- nginx启动时报错
nginx启动时报错 原因:nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed /var/cache/ngin ...
随机推荐
- 【转载】论文笔记系列-Tree-CNN: A Deep Convolutional Neural Network for Lifelong Learning
一. 引出主题¶ 深度学习领域一直存在一个比较严重的问题——“灾难性遗忘”,即一旦使用新的数据集去训练已有的模型,该模型将会失去对原数据集识别的能力.为解决这一问题,本文提出了树卷积神经网络,通过先将 ...
- python模块-----time
说明 time模块提供各种时间相关的功能 与时间相关的模块有:time,datetime,calendar 这个模块的功能不是适用于所有的平台 这个模块中定义的大部分函数是调用C平台上的同名函数实现 ...
- OVS-----CentOS7上搭建基于Open vSwitch的VxLAN隧道实验
一.关于VXLAN VXLAN 是 Virtual eXtensible LANs 的缩写,它是对 VLAN 的一个扩展,是非常新的一个 tunnel 技术,在Open vSwitch中应用也非常多. ...
- mybatis 三剑客 generator配置 、mybatis plugin
generator配置 1.配置pom.xml 导入mysql驱动.mybatis.mybatis-generator的依赖 <dependency> <groupId>org ...
- flirtlib 测试过程
一. 安装flirtlib 1. 安装必要的依赖库 Boost >= 1.36 (submodules math and graph) 这个有了 Qt4 (for the gui)这个也有了 Q ...
- Keepalived详解(四):通过vrrp_script实现对集群资源的监控【转】
一.通过vrrp_script实现对集群资源的监控: Keepalived基础HA功能时用到了vrrp_script这个模块,此模块专门用于对集群中服务资源进行监控.与此模块一起使用的还有track_ ...
- U3D虚拟摇杆制作
来自https://www.cnblogs.com/jiuxuan/p/7453762.html 1.创建两个Image,修改第一个Image名称为 Background,把第二个Image放入 Ba ...
- ubuntu 16.04 登录后黑屏
进入登录界面后黑屏,重新更新英伟达的显卡,也么有起作用. 解决办法,进入登录界面时,进入终端(ctrl+alt+f1),然后修改 grub配置文件,使其每次重启时都检查文件 sudo vi /etc ...
- C/C++ 获取文件大小
在C语言中测试文件的大小,主要使用二个标准函数. 1.fseek 函数原型:int fseek ( FILE * stream, long int offset, int origin ); 参数说明 ...
- HomeBrew 安转beta版软件
今天想装测试版的cocoapods,用 brew install cocoapods 后,总是安装稳定版,就是1.1.0,不是最新的beta版,发现用下面这个命令可以装最新beta版 brew ins ...