Centos7安装Selenium+Chrome+ChromeDriver(应用代码无需设置路径)

1、添加yum源
在 /etc/yum.repos.d/ 目录下新建文件 google-chrome.repo

vim /etc/yum.repos.d/google-chrome.repo
1
向其中添加如下内容:

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

1
2
3
4
5
6
7
2、下载并安装Chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
1
安装时要记住版本号:101.0.4951.54 (不同时间点安装的版本不同,注意修改)


3、安装Chrome Driver
访问 http://chromedriver.storage.googleapis.com/index.html

找到Chrome对应的版本,下载chromedriver_linux64.zip 文件:

wget http://chromedriver.storage.googleapis.com/101.0.4951.41/chromedriver_linux64.zip
1
注意你的版本,需要修改版本号

解压文件:

unzip chromedriver_linux64.zip
1
查找Chrome安装目录

which google-chrome-stable
1
结果返回的是:/bin/google-chrome-stable 不同系统版本可能不同,注意替换。

将 chromedriver_linux64 移动到Chrome安装目录下:

mv chromedriver /bin/
1
4、安装Selenium
pip3 install selenium
1
5、测试使用
python3
1
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("https://www.baidu.com")
1
2
3
4
5
6
7
8
没有报错就OK了
————————————————
版权声明:本文为CSDN博主「小歆Pro」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhangzejin3883/article/details/124686279

posted @ 2023-03-08 14:25  GaoYanbing  阅读(321)  评论(0编辑  收藏  举报