Selenium+PhantomJS使用时报错原因及解决方案(转)
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()
如上,完美解决~
Selenium+PhantomJS使用时报错原因及解决方案(转)的更多相关文章
- Selenium+PhantomJS使用时报错原因及解决方案
问题 今天在使用selenium+PhantomJS动态抓取网页时,出现如下报错信息: UserWarning: Selenium support for PhantomJS has been dep ...
- 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 ...
随机推荐
- WebSocket异步通讯,实时返回数据实例
定义类中的异步方法 using System;using System.Collections.Generic;using System.IO;using System.Linq;using Syst ...
- Confluence 6 整合到支持的附件存储选项
如果你现在正在存储附件到 WebDav 或者你的数据库中.你可以整合附件的存储到文件系统中.当你的附件从数据库中被合并到文件系统后,你存储在数据库中的附件数据就可以从数据库中删除了. 当附件合并进行的 ...
- Rational Rose 2007下载、安装和破解
一.文件下载 (1)DAEMON Tools Lite(虚拟光驱)下载地址 链接:https://pan.baidu.com/s/19L1FT6T1MlyhkfXyobd26A 提取码:drfs (2 ...
- 初识ActiveMQ
消息中间件的初步认识 什么是消息中间件? 消息中间件是利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,可以在分布式架构下扩展进程 ...
- jsp 修饰 Request 及Response
Servlet API包含4个可修饰的类,用于改变Servlet Request以及Servlet Response.这种修饰允许修改 ServletRequest以及ServletResponse或 ...
- PDF文件编辑技巧之PDF书签怎么设置
纸质的文件想要添加书签就直接拿笔书写就可以,Word文件怎么添加书签相信大家也都知道,那么PDF文件的书签要怎么设置的呢,是不是有很多小伙伴不知道该怎么做呢,不要担心,今天小编就来跟大家分享一下在PD ...
- RabbitMQ在java中基础使用
RabbitMQ相关术语: 1.Broker:简单来说就是消息队列服务器实体. 2.Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列. ...
- Two Sum【LeetCode】
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- HDU 1075 What Are You Talking About (stl之map映射)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- mac下安装Brew 警告:Warning: /usr/local/bin is not in your PATH.
终端输入命令 export PATH=/usr/local/bin:$PATH