zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Centos7.6安装chrome和driver

2023-03-15 22:03:57 时间

yum安装google浏览器

1、 创建yum文件

cd 到目录 /etc/yum.repos.d/

cd  /etc/yum.repos.d/

新建文件 google-chrome.repo

vim google-chrome.repo

写入以下内容

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

2、安装 chrome

yum -y install google-chrome-stable --nogpgcheck

3、查看版本

google-chrome --version

无异常则安装成功

安装chromedriver

1、查看和下载driver所需版本

我安装的chrome版本是Google Chrome 91.0.4472.106 。

需要到 https://npm.taobao.org/mirrors/chromedriver/ 下载对应的驱动。

找到后先cd到opt目录下

cd /opt

再通过wget下载

wget https://npm.taobao.org/mirrors/chromedriver/91.0.4472.19/chromedriver_linux64.zip

2、 解压安装

unzip chromedriver_linux64.zip

3、 添加软链接

ln -s /opt/chromedriver /usr/bin/chromedriver

3、测试

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options)

driver.get("http://httpbin.org/get")
print(driver.page_source)
driver.close()
driver.quit()