Selenium support for PhantomJS has been deprecated, please use headless
今天在使用Selenuim+PhantomJS动态抓取网页时,出现如下报错信息:
C:\Python36\lib\site-packages\selenium-3.11.0-py3.6.egg\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 use headless '
意思就是Selenuim已经放弃PhantomJS,了,建议使用火狐或者谷歌无界面浏览器。



要确保机器上安装谷歌浏览器
把chromedriver.exe放在C:\Python27\Scripts路径下
Chrome-headless 模式, Google 针对 Chrome 浏览器 59版 新增加的一种模式,可以让你不打开UI界面的情况下使用 Chrome 浏览器,所以运行效果与 Chrome 保持完美一致。
火狐驱动:https://github.com/mozilla/geckodriver/releases
https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
Geckodriver版本与Firefox版本映射关系
https://blog.csdn.net/u013250071/article/details/78803230
下载驱动后,可以放在python27/scrpts目录下,也可以放在某个目录,设置在环境变量path里面
具体实现代码:
chrome_options = Options()
#Chrome-headless 模式, Google 针对 Chrome 浏览器 59版 新增加的一种模式,可以让你不打开UI界面的情况下使用 Chrome 浏览器,所以运行效果与 Chrome 保持完美一致。
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.driver.set_page_load_timeout(10)
self.driver.maximize_window()
其它使用同 phantomjs 一样
完整python代码
# coding=utf-8
import os
import re
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from datetime import datetime,timedelta
import time
from pyquery import PyQuery as pq
import re import datetime class consumer: def __init__(self):
#通过配置文件获取IEDriverServer.exe路径
# IEDriverServer ='C:\Program Files\Internet Explorer\IEDriverServer.exe'
# self.driver = webdriver.Ie(IEDriverServer)
# self.driver.maximize_window()
# self.driver = webdriver.PhantomJS(service_args=['--load-images=false'])
# self.driver = driver = webdriver.Chrome() # chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
# self.driver = webdriver.Chrome(chrome_options=chrome_options) options = webdriver.FirefoxOptions()
options.set_headless()
# options.add_argument('-headless')
options.add_argument('--disable-gpu')
self.driver = webdriver.Firefox(firefox_options=options)
self.driver.set_page_load_timeout(10)
self.driver.maximize_window() def WriteLog(self, message,date):
fileName = os.path.join(os.getcwd(), 'consumer/' + date + '.txt')
with open(fileName, 'a') as f:
f.write(message)
# http://search.cctv.com/search.php?qtext=消费主张&type=video
def CatchData(self,url='http://search.cctv.com/search.php?qtext=%E6%B6%88%E8%B4%B9%E4%B8%BB%E5%BC%A0&type=video'):
error = ''
try:
self.driver.get(url) selenium_html = self.driver.execute_script("return document.documentElement.outerHTML")
doc = pq(selenium_html) filename = datetime.datetime.now().strftime('%Y-%m-%d')
message = '{0},{1}'.format( '标题', '时间')
filename = datetime.datetime.now().strftime('%Y-%m-%d')
self.WriteLog(message, filename)
pages = doc("div[class='page']").find("a")
# 2018-06-05 00:12:21
pattern = re.compile("\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
for index in range(1,6):
url = "get_data('{0}', '消费主张', 'relevance', 'video', '-1', '1', '', '20', '1')".format(index) self.driver.execute_script(url)
selenium_html = self.driver.execute_script("return document.documentElement.outerHTML")
doc = pq(selenium_html)
print(index)
try:
Elements = doc("div[class='jvedio']").find("a")
for sub in Elements.items():
title = sub.attr('title')
print(title)
ts = pattern.findall(title)
strtime = ''
if ts and len(ts) == 1:
strtime = ts[0]
if strtime:
index1 = title.index(strtime)
title = str(title[0:index1]).replace("•","") title = '\n{0},{1}'.format(title, strtime)
self.WriteLog(title, filename)
except Exception as e:
print("OS error: {0}".format(e)) except Exception as e1:
error = "ex" # python "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.3\helpers\pydev\setup_cython.py" build_ext --inplace obj = consumer() obj.CatchData()
# obj.CatchContent('')
# obj.export('')
Selenium support for PhantomJS has been deprecated, please use headless的更多相关文章
- selenium抓取淘宝数据报错:warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless
ssh://root@192.168.33.12:22/root/anaconda3/bin/python3 -u /www/python3/maoyantop100/meishi_selenium. ...
- 使用PhantomJS报warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '解决方法
selenium已经放弃PhantomJS了,建议使用火狐或者谷歌无界面浏览器.使用无界面浏览器Selenium+Headless Firefox Selenium+Headless Firefox和 ...
- PhantomJS报错warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
原因:Selenuim已经放弃PhantomJS3.x了,建议使用火狐或者谷歌无头浏览器. 解决方法: 1.phantomjs降级,换个2.x版本的 2.使用无头浏览器,示例代码(自己改了改,如有错误 ...
- 新版的 selenium已经放弃PhantomJS改用Chorme headless
新版的 selenium已经放弃PhantomJS改用Chorme headless 使用pip show selenium显示默认安装的是3.1.3版本目前使用新版selenium调用Phant ...
- PhantomJS的替代品--无头浏览器(Headless Chrome)
在使用PhantomJS时候,出现提示: UserWarning: Selenium support for PhantomJS has been deprecated, please use hea ...
- selenium + firefox/chrome/phantomjs登陆之模拟点击
登陆之模拟点击 工具:python/java + selenium + firefox/chrome/phantomjs (1)windows开发环境搭建 默认已经安装好了firefox 安装pip ...
- selenium support
org.openqa.selenium.support.ui.Select select = new org.openqa.selenium.support.ui.Select(driver.fi ...
- 第三百三十七节,web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS
第三百三十七节,web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS PhantomJS虚拟浏览器 phantomjs 是一个基于js的webkit内核无头浏览器 ...
- 在 Selenium 中让 PhantomJS 执行它的 API
from selenium import webdriver driver = webdriver.PhantomJS() script = "var page = this; page.o ...
随机推荐
- java多线程快速入门(十三)
死锁产生的原因(必须有两个线程.必须有多个锁.锁之间必须有引用的过程) package com.cppdy; class MyThread9 implements Runnable { private ...
- &&(与),||(或),|,!(非)
&&(与),||(或),|,!(非) 只能用于布尔值 //: object/test.java package object; import java.util.*; public c ...
- Luogu P3294 【[SCOI2016]背单词】
阅读理解题 ...... $Trie$ 后缀问题不好处理,我们把它转化为前缀问题,用字典树解决问题 贪心 容易想到,一个串的后缀要先于它插入 对于一个串和其若干后缀串,容易想到,我们要先插入后缀串 然 ...
- Linux中查找当前目录下占用空间最大的前10个文件
du命令 计算出单个文件或者文件夹的磁盘空间占用 -a或--all:包含全部的文件系统: --block-size=<区块大小>:以指定的区块大小来显示区块数目: -h或--human-r ...
- POJ 1742 Coins 【多重背包DP】
题意:有n种面额的硬币.面额.个数分别为A_i.C_i,求最多能搭配出几种不超过m的金额? 思路:dp[j]就是总数为j的价值是否已经有了这种方法,如果现在没有,那么我们就一个个硬币去尝试直到有,这种 ...
- POJ 3262 Protecting the Flowers 【贪心】
题意:有n个牛在FJ的花园乱吃.所以FJ要赶他们回牛棚.每个牛在被赶走之前每秒吃Di个花朵.赶它回去FJ来回要花的总时间是Ti×2.在被赶走的过程中,被赶走的牛就不能乱吃 思路: 先赶走破坏力大的牛假 ...
- python全栈开发day48-jqurey自定义动画,jQuery属性操作,jQuery的文档操作,jQuery中的ajax
一.昨日内容回顾 1.jQuery初识 1).使用jQuery而非JS的六大理由 2).jQuery对象和js对象转换 3).jQuery的两大特点 4).jQuery的入口函数三大写法 5).jQu ...
- LR报错Error -27780: [GENERAL_MSG_CAT_SSL_ERROR]connect to host "XXX.XXX.com" failed解决方法
- 【Java】 剑指offer(6) 重建二叉树
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的 ...
- Java 处理 iphone拍照后 图片EXIF属性翻转90度的方法
http://blog.csdn.net/z69183787/article/details/50320821 Java获取照片EXIF信息 http://blog.csdn.net/ghsau/ar ...