selenium+headless chrome安装使用

pip install selenium

因为phantomJS将停止维护,所以建议使用headless chrome
ChromeDriver is a separate executable that WebDriver uses to control Chrome.

1、确保谷歌浏览器安装在可以找到的位置(默认位置或自己指定的位置)。
如果不是默认位置,则需要用下面的代码来指定谷歌浏览器的安装位置:
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");

2、下载你系统上所需要的ChromeDriver文件,windows所需下载地址为:
https://chromedriver.storage.googleapis.com/index.html?path=2.35/

3、帮助WebDriver找到你下载的ChromeDriver文件:
将ChromeDriver文件存放在PATH目录下或

from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver')

4、(可选)启动和退出ChromeDriver server需要一些时间,所以提供了两种方法来
解决这个问题:
1、使用ChromeDriverService
2、作为一个服务器单独启动ChromeDriver server,然后用Remote WebDriver连接它。

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')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.baidu.com")
print(driver.title)
driver.quit()

参考链接:
https://sites.google.com/a/chromium.org/chromedriver/home 介绍地址
https://sites.google.com/a/chromium.org/chromedriver/getting-started 入门地址

转载于:https://www.cnblogs.com/zxpo/p/8288663.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值