【问题标题】:chrome fails to load with python selenium chromedriverchrome 无法使用 python selenium chromedriver 加载
【发布时间】:2017-11-02 11:29:27
【问题描述】:

我已经在我的 PC 上使用 Ubuntu 17.10 测试了代码。 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)

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

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

谢谢!

【问题讨论】:

  • 请粘贴来自终端/usr/bin/google-chrome --disable-background-networking ...and the rest of it的执行命令输出
  • /usr/bin/google-chrome --disable-background-networking 给出 [3513:3513:1102/221503.908274:ERROR:zygote_host_impl_linux.cc(88)] 在没有 --no- 的情况下以 root 身份运行不支持沙箱。见crbug.com/638180
  • /usr/bin/google-chrome --disable-background-networking --no-sandbox 给出 [1102/221543.036310:ERROR:nacl_helper_linux.cc(310)] NaCl 助手进程在没有沙箱的情况下运行!您很可能需要正确配置 SUID 沙箱
  • 我在调试时和在此处发布之前看到了“--no-sandbox”提示。没有想过将其作为 chromedriver 的 chrome_options。有用!您可以将其发布为答案吗?非常感谢!

标签: python google-chrome selenium selenium-chromedriver


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多