一、系统环境
二、安装步骤
- 下载chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
- 安装chrome
yum -y install ./google-chrome-stable_current_x86_64.rpm
- 查看chrome版本号:
- 下载chromedriver
wget https://npm.taobao.org/mirrors/chromedriver/83.0.4103.39/chromedriver_linux64.zip
注意chromedriver的版本【下载地址1,下载地址2】,一定要与你安装的chrome版本号相对应。
- 解压chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver /usr/bin/
- 安装selenium
pip3 install selenium
三、测试
新建测试文件baidu.py
,内容如下:
from selenium import webdriver
print('开始...')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get('https://www.baidu.com/')
print(driver.title)
driver.quit()
print('结束!')
最后:对你有所帮助的话,记得点赞哦!