[英]Xvfb Selenium headless Chrome on Linux in Python
I'm trying to run chrome headless with selenium in Python. 我正在尝试在python中使用硒无头运行chrome。 I tried
xvfb-run -a python3 message.py
And i get this error: 我尝试了
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)
And initialize(): 和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')
I'm using Python 3.5 and chromedriver 2.33.506178 for Linux32 (Ubuntu as Server without Desktop) I tested the same code on my other pc with linux mint, all works fine. 我在Linux32上使用Python 3.5和chromedriver 2.33.506178(Ubuntu作为不带桌面的服务器)在装有Linux Mint的另一台PC上测试了相同的代码,一切正常。
Hope you can help me :) 希望你能帮我 :)
After checking my actual rights of writing/reading/executing I found my mistake. 在检查了我实际的写/读/执行权利之后,我发现了我的错误。 chromedriver weren't able to load while trying to execute with root rights.
尝试使用root权限执行操作时,chromedriver无法加载。 After I changed chromedrivers permission all works fine now.
更改chromedrivers权限后,现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.