[英]Try to start chrome driver on linux with selenium webdriver
[英]Selenium Chrome Driver Under Linux
尝试让Webdriver在Linux下产生时花了一些时间。
我在CentOS 7.3上已经安装了Chrome,Chromium和许多其他python库。 我在跑:
chrome_options = webdriver.ChromeOptions()
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)
具有不同路径的替代方案在Windows下运行良好,因此问题肯定出在我的Linux移植端口上。
我跑了:
chmod a+x chromedriver
而且它在root下运行,因此它应该可以访问chromedriver。
如果我通过带有超时的线程池生成它,则每次都会达到该超时。 正常运行它最终会引发错误:
Traceback (most recent call last):
File "Skyscrapercomp.py", line 492, in <module>
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, 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.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.10.0-514.2.2.el7.x86_64 x86_64)
我的主要收获是“ Chrome无法启动:异常退出”,这并没有给我带来太多帮助。
我已经使用pip来安装最新的Selenium和Yum来安装Chromium和Chrome。 感觉有点沉迷于水中,不确定下一步是什么,所以我非常感谢朝着正确方向前进的产品。
/更新:
我在/ usr / bin中检查了google-chrome是否存在,这是它想要的默认位置。
还尝试将chromedriver放在/ usr / bin中,但不给它一个位置:
TheBrowser = webdriver.Chrome()
TheBrowser.get("http://www.google.com")
print TheBrowser.page_source.encode('utf-8')
但这给出了相同的错误。
尝试使用日志记录来查找问题:
chrome_options = webdriver.ChromeOptions()
service_log_path = 'chromedriver.log'
service_args = ['--verbose']
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options, service_args=service_args, service_log_path=service_log_path)
就我而言,显示出现错误(Ubuntu服务器上没有X11)。 这对我有帮助:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start() # don't forget to .stop() it at the end of program
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.