铬无法加载python selenium chromedriver

时间:2017-11-02 11:29:27

标签: python google-chrome selenium selenium-chromedriver

我已经使用Ubuntu 17.10在我的电脑上测试了代码。 Chrome启动时带有UI,因此一切正常。

Vultr instasnce是安装了Ubuntu 16.04,Python 3,Selenium,Google-Chrome,Chromedriver和xvfb。默认用户是root。

chromedriver-2.33.506092在/ usr / bin / chromedriver上,而 Google-Chrome-62.0.3202.75位于/ usr / bin / google-chrome

但是,在Vultr实例上运行它会出现此错误: https://pastebin.com/RJX6Ynxe

以下是代码的一部分。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options)

这是服务日志: https://pastebin.com/s6Nw3Jxc

有人知道如何解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

此问题仅与Chrome驱动程序有关。问题的原因描述为here

要在无头模式下运行chrome时要具体,您需要包含标记--no-sandbox

chrome_options.add_argument('--no-sandbox')