ChromeDriver is assuming that Chrome has crashed 一直无法打开,总是崩溃

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 3.10.0-862.el7.x86_64 x86_64)

 

使用selenium webdriver调用Chrome发现一直报错 

--no-sandbox

如果不加一直报错,下面是提供弹幕

#coding = utf-8
from selenium import webdriver
chrome_options= webdriver.ChromeOptions()

chrome_options.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错
chrome_options.add_argument('window-size=1920x3000') #指定浏览器分辨率
chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度
chrome_options.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败

browser = webdriver.Chrome("/root/note/Python/myTools/Scrapy/driver/chromedriver",chrome_options=chrome_options)

browser.get("https://www.baidu.com")

print(browser.page_source)
 

你可能感兴趣的:(爬虫)