1. 安装chrome
首先安装google的epel源
2 .安装selenium:
踩过坑,建议Linux的放到:/usr/bin/
4 . 为chromedriver授权
参考资料:https://cloud.tencent.com/developer/article/1432921
首先安装google的epel源
代码: 全选
我的是Centos 7, 最后安装完毕后在/optvi /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-stable
2 .安装selenium:
代码: 全选
3 . chromedriver下载
pip3 install --upgrade pip
pip3 install selenium
代码: 全选
找到chrome对应的chromedriver 版本,并下载https://npm.taobao.org/mirrors/chromedriver/
代码: 全选
将下载的chromedriver 放到脚本同级目录调用wget https://npm.taobao.org/mirrors/chromedriver/78.0.3904.70/chromedriver_linux64.zip
踩过坑,建议Linux的放到:/usr/bin/
4 . 为chromedriver授权
代码: 全选
5 . 测试代码 ts.py
chmod 755 chromedriver
代码: 全选
6 . 测试结果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异常, root用户必须加
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()
参考资料:https://cloud.tencent.com/developer/article/1432921