CentOS7.X安装Chrome和chromedriver

一、下载安装Chrome

安装相关依赖

yum install liberation-fonts -y
yum install vulkan -y
yum -y install redhat-lsb*
yum -y install libXss*
yum -y install libappindicator*
yum -y install libgbm

下载google-chrome 最新RPM安装包

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

安装google-chrome

rpm -ivh google-chrome-stable_current_x86_64.rpm

查看google-chrome版本

google-chrome --version

二、下载安装chromedriver

下载对应版本的chromedriver(这里以108.0.5359.71版本为例)

wget https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip

unzip解压压缩包

unzip chromedriver_linux64.zip

设置可执行权限

chmod +x chromedriver

将其移至/usr/bin/目录下

mv chromedriver /usr/bin/

命令行输入chromedriver验证是否安装成功

[root@iZ2zeg ~]# chromedriver
Starting ChromeDriver 108.0.5359.71 (1e0e3868ee06e91ad636a874420e3ca3ae3756ac-refs/branch-heads/5359@{#1016}) on port 9515
Only local connections are allowed.

三、selenium验证能否正常使用

from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument('headless')        #linux系统需设置无可视化界面
option.add_argument('--no-sandbox')    #解决DevToolsActivePort文件不存在的报错
driver = webdriver.Chrome(chrome_options=option)
driver.get('https://www.baidu.com')
print(driver.title)
driver.quit()

输出“百度一下,你就知道”说明能够正常使用。

出现如下报错信息:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

添加option.add_argument('--no-sandbox') ,即可解决找不到DevToolsActivePort的报错

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值