繁体   English   中英

Linux上使用Python的Xvfb Selenium无头Chrome

[英]Xvfb Selenium headless Chrome on Linux in Python

我正在尝试在python中使用硒无头运行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)

和initialize():

   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的另一台PC上测试了相同的代码,一切正常。

希望你能帮我 :)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM