chromedriver配置


需要先安装chrome浏览器,添加chrome源

sudo vim /etc/yum.repos.d/google-chrome.repo

添加以下内容

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

安装yum -y install google-chrome-stable,国内可能无法访问,使用yum -y install google-chrome-stable --nogpgcheck或者把gpgcheck改为0

下载chromedriver,解压放在/usr/bin/下。

which chromedriver测试是否成功。

如果报selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist, 或者类似的错误, 尝试在初始化时添加参数--no-sandbox--disable-dev-shm-usage, 例如:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


options = Options()
options.add_argument("--headless")
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument(
    'user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.baidu.com")


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM