centos7无GUI运行selenium chromedriver 亲测可用!

1. 安装chrome

首先安装google的epel源html

vi /etc/yum.repos.d/google.repo
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

yum update , 而后yum install google-chrome-stablepython

2. chromedriver下载

https://npm.taobao.org/mirrors/chromedriver/linux

找到chrome对应的chromedriver 版本,并下载web

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

将下载的chromedriver 放到脚本同级目录调用chrome

3 . 为chromedriver受权

chmod 755 chromedrivernpm

4. 测试代码 ts.py

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')
chrome_options.add_argument('--no-sandbox')    # 禁止沙箱模式,不然肯能会报错遇到chrome异常
url="https://www.west.cn/login.asp"
brower=webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
brower.get(url)
print(brower.current_url)
brower.get("https://www.west.cn/Manager/")
print(brower.current_url)
brower.quit()

5. 测试结果

参考连接:centos

centos 7 无gui界面运行selenium + chrome模拟登录api

在CentOS7上使用chrome(selenium)less

selenium操做chrome时的一些配置测试

【Linux】CentOS7上解压zip须要安装uzip

相关文章
相关标签/搜索