Selenium+PhantomJS替代方案
问题描述:
python3在使用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了,建议使用火狐或者谷歌无界面浏览器。
so,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.baidu.com/")
print(driver.page_source)
driver.close() if __name__ == '__main__':
main()
Selenium+Headless Chrome
前提条件:
- 本地安装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()
python selenium模块使用出错,找不到路径
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Windows环境下:
1、下载geckodriver.exe:
地址:https://github.com/mozilla/geckodriver/releases
请根据系统版本选择下载;(如Windows 64位系统)
2、下载解压后将getckodriver.exe复制到Firefox的安装目录下,如(C:\Program Files\Mozilla Firefox),并在环境变量Path中添加路径:C:\Program Files\Mozilla Firefox;
3.重启cmd或IDLE再次运行代码即可
ubuntu16.04环境下
1、下载 geckodriverckod
地址: https://github.com/mozilla/geckodriver/releases
2、解压后将geckodriverckod 存放至 /usr/local/bin/ 路径下即可
参考链接:
https://blog.csdn.net/liu5257/article/details/53437878
https://blog.csdn.net/u010358168/article/details/79749149
Selenium+PhantomJS替代方案的更多相关文章
- selenium + phantomjs 爬取落网音乐
题记: 作为一个业余程序猿,最大的爱好就是电影和音乐了,听音乐当然要来点有档次的.落网的音乐的逼格有点高,一听听了10年.学习python一久了,于是想用python技术把落网的音乐爬下来随便听. 目 ...
- 使用selenium+phantomJS实现网页爬取
有些网站反爬虫技术设计的非常好,很难采用WebClient等技术进行网页信息爬取,这时可以考虑采用selenium+phantomJS模拟浏览器(其实是真实的浏览器)的方式进行信息爬取.之前一直使用的 ...
- Selenium + PhantomJS + python 简单实现爬虫的功能
Selenium 一.简介 selenium是一个用于Web应用自动化程序测试的工具,测试直接运行在浏览器中,就像真正的用户在操作一样 selenium2支持通过驱动真实浏览器(FirfoxDrive ...
- 数据抓取的艺术(一):Selenium+Phantomjs数据抓取环境配置
数据抓取的艺术(一):Selenium+Phantomjs数据抓取环境配置 2013-05-15 15:08:14 分类: Python/Ruby 数据抓取是一门艺术,和其他软件不同,世界上 ...
- 动态网页爬取例子(WebCollector+selenium+phantomjs)
目标:动态网页爬取 说明:这里的动态网页指几种可能:1)需要用户交互,如常见的登录操作:2)网页通过JS / AJAX动态生成,如一个html里有<div id="test" ...
- python+selenium自动化软件测试(第6章):selenium phantomjs页面解析使用
我们都知道Selenium是一个Web的自动化测试工具,可以在多平台下操作多种浏览器进行各种动作,比如运行浏览器,访问页面,点击按钮,提交表单,浏览器窗口调整,鼠标右键和拖放动作,下拉框和对话框处理等 ...
- 学习用java基于webMagic+selenium+phantomjs实现爬虫Demo爬取淘宝搜索页面
由于业务需要,老大要我研究一下爬虫. 团队的技术栈以java为主,并且我的主语言是Java,研究时间不到一周.基于以上原因固放弃python,选择java为语言来进行开发.等之后有时间再尝试pytho ...
- 利用Selenium+PhantomJS 实现截图
using OpenQA.Selenium; using OpenQA.Selenium.PhantomJS; using System; using System.Drawing; using Sy ...
- python selenium+phantomjs alert()弹窗报错
问题:用selenium+phantomjs 模拟登陆,网页用JavaScript的alert("登陆成功")弹出框,但是用switch_to_alert().accept()报错 ...
随机推荐
- 《你必须掌握的Entity Framework 6.x与Core 2.0》勘误
第5章 5.1.1----致谢网友[宪煌] public virtual ICollection Post {get;set;} 修改为 public virtual ICollection<P ...
- IP包头结构详解
版本号(Version):长度4比特.标识目前采用的IP协议的版本号.一般的值为0100(IPv4),0110(IPv6) IP包头长度(Header Length):长度4比特.这个字段的作用是为了 ...
- 我的Qt历程1:第一个Qt程序
1.启动Qt,按照红圈内所标注顺序执行操作. 2.按下Choose键后,在“名称”栏目里给程序起名字(不要是汉字名字). 3.在“创建路径”栏目里指定程序将要使用的路径(不能用汉字路径). 4.在“类 ...
- JS JavaScript模块化(ES Module/CommonJS/AMD/CMD)
前言 前端开发中,起初只要在script标签中嵌入几十上百行代码就能实现一些基本的交互效果,后来js得到重视,应用也广泛起来了, jQuery,Ajax,Node.Js,MVC,MVVM等的助力也使得 ...
- Spring Boot与缓存
---恢复内容开始--- JSR-107.Spring缓存抽象.整合Redis 一.JSR107 Java Caching定义了5个核心接口,分别是CachingProvider, CacheMana ...
- 【C语言】位运算
编写一个函数getbits,从一个16位的单元中取出某几位(即该几位保留原值,其余位0).函数调用形式为getbits(value,n1,2).----简单题目遇到想不到的问题 c语言位运算经典问题: ...
- zookeeper-3.5.4-beta安装
官网地址 https://zookeeper.apache.org/ 下载文件解压进入conf目录下将zoo_sample.cfg名称修改为zoo.cfg # The number of millis ...
- DAY18、常用模块
一.random:随机数1.(0,1) 小数:random.random()2.[1,10] 整数:random.randint(1,10)3.[1,10) 整数:random.randrange(1 ...
- NLP句子表征,NLP 的巨人肩膀(下):从 CoVe 到 BERT (转载)
深度长文:NLP的巨人肩膀(上):https://www.jiqizhixin.com/articles/2018-12-10-17 NLP 的巨人肩膀(下):从 CoVe 到 BERT: https ...
- bugku web 矛盾
$num=$_GET['num'];if(!is_numeric($num)){echo $num;if($num==1)echo 'flag{**********}';} 首先要判断get得到的数据 ...