chrome 无法使用 python selenium chromedriver 加载

y2k*_*bug 3 python selenium google-chrome selenium-chromedriver

我已经使用 Ubuntu 17.10 在我的 PC 上测试了代码。Chrome 与 UI 一起启动,所以一切正常。

Vultr 实例安装了 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)
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢!

dea*_*908 7

此问题仅与 chrome 驱动程序有关。此处描述了问题的原因。

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

chrome_options.add_argument('--no-sandbox')
Run Code Online (Sandbox Code Playgroud)