linux - Linux 上的 Xvfb Selenium headless Chrome 和 Python

标签 linux python-3.x google-chrome selenium-chromedriver

我正在尝试在 Python 中使用 selenium headless 运行 chrome。 我试过 xvfb-run -a python3 message.py 我得到这个错误:

Traceback (most recent call last):
  File "message.py", line 388, in <module>
    initialize()
  File "message.py", line 54, in initialize
    driver = webdriver.Chrome(chrome_options = chrome_options)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.33.506178 (69ae10f91723897591ef1a3b465aa5d35011eb5e),platform=Linux 3.13.0-96-generic x86)

和初始化():

   chrome_options = webdriver.ChromeOptions()
   chrome_options.add_argument("--headless")
   chrome_options.add_argument("--no-sandbox")
   chrome_options.add_argument("--verbose")
   chrome_options.add_argument("--log-path=chrome.log")
   chrome_options.add_argument("window-size=1200x600")
   chrome_options.add_argument("user-data-dir=\\")
   driver = webdriver.Chrome(chrome_options = chrome_options)
   driver.get('http://google.com')

我在 Linux32 上使用 Python 3.5 和 chromedriver 2.33.506178(Ubuntu 作为没有桌面的服务器) 我在我的另一台电脑上用 linux mint 测试了相同的代码,一切正常。

希望你能帮助我:)

最佳答案

在检查了我的写/读/执行的实际权限后,我发现了我的错误。 chromedriver 在尝试以 root 权限执行时无法加载。 在我更改 chromedrivers 权限后,现在一切正常。

关于linux - Linux 上的 Xvfb Selenium headless Chrome 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48230322/

相关文章:

javascript - Chrome 的控制台自动完成

linux - 纯文本文件转换为html文件

linux - 线程和任务的数量是否正常?

linux - 哪些目录应该放在 Linux 服务器 Amazon EC2 的新卷中

python - 查找嵌套整数列表的总和

google-chrome - Chrome 53 如何让ui变小?

linux - linux和windows进程的区别

python - 我怎样才能调用神奇的 `__contains__` 方法?

python - Django makemigrations 不断进行相同的更改

google-chrome - 本地主机中的页面不断加载