走过了一堆坑… 大部分都是复制粘贴的博客。。
1、安装linux chrome
https://www.google.cn/chrome/ 下载源,选择.rpm
安装:rpm -ivh google-chrome-stable_current_x86_64.rpm
2、安装linux webdriver
cd /usr/local/share
wget -N https://npm.taobao.org/mirrors/chromedriver/92.0.4515.43/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
3、注意!chrome+webdriver注意大版本号要一致!
– 查看chrome版本号
google-chrome --version
– webdriver版本号
chromedriver -version
4、验证
yum install python-pip
pip install selenium
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('headless')
option.add_argument('no-sandbox')
option.add_argument('disable-dev-shm-usage')
option.add_argument('disable-gpu')
browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=option)
browser.get("http://10.10.3.40:8865/")
print(browser.current_url)
browser.quit()