CentOS安装Chrome+ChromeDriver【设置无界面浏览器】

安装Chrome
指定yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

下载并安装
curl https://intoli.com/install-google-chrome.sh | bash
ldd /opt/google/chrome/chrome | grep "not found"

测试浏览器
google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/
安装ChromeDriver

下载地址:http://chromedriver.storage.googleapis.com/index.html

查看版本号(注意下载对应版本号的驱动)
google-chrome --version

下载安装包
wget https://npm.taobao.org/mirrors/chromedriver/72.0.3626.7/chromedriver_linux64.zip

解压安装包
unzip chromedriver_linux64.zip

将可执行文件移到bin目录  (Mac环境改为 /usr/local/bin 即可)
mv chromedriver /usr/bin/
测试代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')    # 设置无界面
options.add_argument('--no-sandbox')  # root用户下运行代码需添加这一行
driver = webdriver.Chrome(options=options)
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.quit()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值