步骤1:CentOS 7.9下安装Google浏览器。(安装方法见:http://blog.100shijuan.com/post/289.html)
步骤2:检查Google浏览器版本。
google-chrome --version
步骤3:下载对应版本的ChromeDriver
3.1、114及之前的版本可以通过点击(https://chromedriver.storage.googleapis.com/index.html)下载chromedriver,根据版本号(只看大版本)下载对应文件;
3.2、116版本通过点击(https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/win64/chromedriver-win64.zip)下载chromedriver,便可直接下载压缩包;
3.3、117/118/119版本通过点击(https://googlechromelabs.github.io/chrome-for-testing/)进入到 Chrome for Testing availability;
注意:到匹配的版本的驱动,只需要保证版本号前面的3段匹配即可。如:119.0.6045
下载命令:
wget {下载URL}
例如:
wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/119.0.6045.105/linux64/chromedriver-linux64.zip
步骤4:查看
ls
步骤5:解压压缩包,注意压缩包名字
unzip chromedriver_linux64.zip # 解压压缩包 ls # 查看当前文件列表 cd chromedriver-linux64 # 进入压缩文件夹 ls # 查看当前文件列表 mv chromedriver /usr/bin/ # 然后移动到 /usr/bin/ 目录 chmod +x /usr/bin/chromedriver # 加入系统变量
步骤6:测试
from selenium import webdriver import time import re from selenium.webdriver.common.by import By opts = webdriver.ChromeOptions() opts.add_argument("--headless") opts.add_argument("--disable-gpu") opts.add_argument("--no-sandbox") chrome = webdriver.Chrome(options=opts) chrome.get("http://www.baidu.com") print(chrome.title) chrome.quit()
结果如下:
还没有评论,来说两句吧...