问题

今天在使用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 FirefoxSelenium+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使用时报错原因及解决方案的更多相关文章

  1. Selenium+PhantomJS使用时报错原因及解决方案(转)

    Selenium+PhantomJS使用时报错原因及解决方案     问题 今天在使用selenium+PhantomJS动态抓取网页时,出现如下报错信息: UserWarning: Selenium ...

  2. Selenium+PhantomJS使用时报错原因

    运行下面代码:'''PhantomJS运用''' from selenium import webdriverimport time # 通过keys模拟键盘from selenium.webdriv ...

  3. 分析https网页加载http资源导致的页面报错原因及其解决方案

    https网页加载http资源导致的页面报错及解决方案 https是当下的网站的主流趋势,甚至像苹果这样的大公司,则完全要求用户必须使用https地址. 然而对于以前http链接来说,我们往往就存在一 ...

  4. angularJS中$http.get( ).success( )报错原因及解决方案

    一.问题描述: 电脑安装的angular1.6.7版本,项目中使用了$http.get( ).success( ),控制台报错: $http.get(...).success is not a fun ...

  5. ie7,8下__flash__addCallback报错原因及解决方案

    首先附张图,以直观说明错误的现象:(ie7.8)

  6. C# ODP.NET 调用Oracle函数返回值时报错的一个解决方案

    有人在社区问到:C#调用Oracle中自定义函数的返回值时,无法正常调用.但在PL/SQL中正常调用返回. 于是动手一试: 1.准备函数(Oralce 11g.2.0.0.4) CREATE OR R ...

  7. Selenium chromeDriver启动时报错:session not created: This version of ChromeDriver only supports Chrome

    解决方案: 这是因为ChromeDriver与本地chrome浏览器的版本不一致导致 ChromeDriver下载地址:http://npm.taobao.org/mirrors/chromedriv ...

  8. python中用selenium调Firefox报错问题

    python在用selenium调Firefox时报错: Traceback (most recent call last):  File "G:\python_work\chapter11 ...

  9. nginx启动时报错

    nginx启动时报错 原因:nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed /var/cache/ngin ...

随机推荐

  1. python标准库之argparse

    argparse的使用 argparse 是 Python 内置的一个用于命令项选项与参数解析的模块,通过在程序中定义好我们需要的参数,argparse 将会从 sys.argv 中解析出这些参数,并 ...

  2. hibernate框架学习之核心配置文件

    hibernate.cfg.xml <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration ...

  3. Codeforces Educational Round 37

    Solved   CodeForces 920A Water The Garden   Solved   CodeForces 920B Tea Queue   Solved   CodeForces ...

  4. Linux内核初探

    内存管理之内存寻址 内存管理是迄今为止Unix内核中最复杂的活动 虚拟内存: 所有新近的Unix系统都提供一种有用的抽象, 叫作虚拟内存(virtual memory): 虚拟内存可以理解为一种逻辑层 ...

  5. css3 - 旋转的木马

    参考资料: 张鑫旭  : http://www.zhangxinxu.com/wordpress/2012/09/css3-3d-transform-perspective-animate-trans ...

  6. 快速解决PHP调用Word组件DCOM权限的问题

    1. 首先必须要在电脑上安装 Office 2. windows+r : 输入 dcomcnfg.exe 打开组件服务,然后双击 组件服务 ==> 双击 计算机 ==> 双击 我的电脑 = ...

  7. most asked interview questions for C/C++

    1.   compared to prefix  ++, postfix increment needs one more step to create a temporary variable? w ...

  8. 如何在eclipse中对项目进行重新编译

    有时由于eclipse异常关闭,当我们重启Eclipse,在启动项目时,会报错,说:ClassNotFound类似的错误,引起这种问题的原因可能是由于,Eclipse异常关闭引起的. 解决:在一个项目 ...

  9. 基于centos7下appium环境搭建

    事件背景: 前几日在群里看到关总说他的server端是搭建在linux环境下,包括对客户端与服务端的交互处理,感觉整体思路清晰可鉴,于是就想尝试,动手实践,接着从环境搭建开始搞起,于是就有了这篇文章, ...

  10. Linux 的 OOM 终结者(Out Of Memory killer)

    现在是早晨6点钟.已经醒来的我正在总结到底是什么事情使得我的起床闹铃提前了这么多.故事刚开始的时候,手机铃声恰好停止.又困又烦躁的我看了下手机,看看是不是我自己疯了把闹钟调得这么早,居然是早晨5点.然 ...