to PhantomJS:爱过

前言

 selenium和phantomjs相识在永远漆黑的服务器,越来越优秀的selenium最终还是放弃了不常打理自己的phantomjs,投入了越来越完美的大众情人chrome的怀抱。

使用场景

 之前有动态网页的爬取需求都是通过selenium+phantomjs解决的,今天在测试之前爬虫的时候看到如果提示:

 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已经不再支持,请使用无头浏览器。

于是服务器上一直用phantomjs的我,也替换成了chrome,因为chrome 59版本更新的新特性Headless mode

核心代码如下:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

# chrome_options.binary_location = '/opt/google/chrome/chrome'

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://www.baidu.com")
driver.save_screenshot("baidu.png")

    书读得越多而不加思考,你就会觉得你知道得很多;而当你读书思考得越多的时候,你就会越清楚地看到,你知道得还很少。--伏尔泰

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值