我已经在我的 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
有人知道怎么解决吗?
谢谢!
最佳答案
此问题仅与 chrome 驱动程序有关。描述了问题的原因 here .
具体来说,当您在 headless 模式下运行 chrome 时,您需要包含标志 --no-sandbox
:
chrome_options.add_argument('--no-sandbox')
关于python - chrome 无法使用 python selenium chromedriver 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47074208/