您的位置:首页 > 博客中心 > 网络系统 >

linux安装selenium+chrome

时间:2022-04-03 15:10

1. 安装 selenium

pip3 install selenium

2. 安装 ChromeDriver

yum install chromedriver.x86_64

3. 安装 Chrome

  1. 配置源,终端复制执行下面的代码
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
  1. 安装 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()

使用以下配置

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()

本类排行

今日推荐

热门手游