Centos7搭建Chrome + ChromeDrier无界面浏览器

Centos7搭建Chrome + ChromeDrier[无界面浏览器]

安装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/
安装并执行成功后会在执行的当前路径下出现一个screenshot.png文件

安装ChromeDriver

下载地址(1):https://chromedriver.storage.googleapis.com/index.html
下载地址(2):https://npm.taobao.org/mirrors/chromedriver/

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

下载安装包
wget https://npm.taobao.org/mirrors/chromedriver/(对应版本)/chromedriver_linux64.zip

解压安装包
unzip unzip chromedriver_linux64.zip

将可执行文件移动到bin目录
mv chromedriver /usr/bin/

测试代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

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

本文拷贝:https://blog.csdn.net/weixin_40476348/article/details/85992293

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值