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 ...
随机推荐
- 查看oracle 用户执行的sql语句历史记录
select * from v$sqlarea t order by t.LAST_ACTIVE_TIME desc
- 【ARTS】01_20_左耳听风-20190325~20190331
zz## ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 ...
- 【转】Python标准模块--importlib
[转]Python标准模块--importlib 作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 P ...
- NodeJS基础教程
关于 本书致力于教会你如何用Node.js来开发应用,过程中会传授你所有所需的“高级”JavaScript知识.本书绝不是一本“Hello World”的教程. 状态 你正在阅读的已经是本书的最终版. ...
- Linux内核之进程地址空间
Linux内核之进程地址空间 内核中的函数以相当直接了当的方式获得动态内存: __get_free_pages 或 alloc_pages从分区页框分配器中获得页框; kmem_cache_alloc ...
- 在Centos7 上安装SVN
https://blog.csdn.net/crossangles_2017/article/details/78553266 1.安装 使用yum安装非常简单: yum install subver ...
- ASP.NET MVC5高级编程 之 视图
1.1理解视图约定 当创建一个项目模版时,可以注意到,项目以一种非常具体的方式包含了一个结构化的Views目录.在每一个控制器的View文件夹中,每一个操作方法都有一个同名的视图文件与其对应.这就提供 ...
- emoji错误:ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value:
1 前言 由于mysql数据库要存储微信昵称,但是当微信昵称带有emoj表情会出现标题的错误. 然后发现是emoj编码是4个字节保存的,于mysql数据库编码格式utf8默认保存的是1到3个字节. 2 ...
- linux进程内存布局
一个程序本质上都是由 BSS 段.data段.text段三个组成的.这样的概念在当前的计算机程序设计中是很重要的一个基本概念,而且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统运行时的内存大小分 ...
- Vue中的render函数随笔
使用vue-cli创建项目后,再main.js里面有这样一段代码: new Vue({ render:h => h(App) }).$mount('#app') render函数是渲染一个视图, ...