1. 安装 selenium
pip3 install selenium
pip3 安装参考
2. 安装 ChromeDriver
yum install chromedriver.x86_64
3. 安装 Chrome
- 配置源,终端复制执行下面的代码
cat << EOF > /etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub
EOF
- 安装 chrome
yum install google-chrome-stable
4.测试
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.baidu.com/')
print( driver.title )
driver.quit()
如果遇到错误"unknown error: DevToolsActivePort file doesn't exist " 使用以下配置
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.baidu.com/')
print( driver.title )
driver.quit()
网友评论