我尝试使用selenium
和chromedriver
从网站上抓取文件。我已将chrome和chromedriver更新到当前级别,但收到以下消息:
Traceback (most recent call last):
File "<stdin>", line 128, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=64.0.3282.167)
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.10.0-40-generic x86_64)
是否有处理此错误的建议? SessionNotCreatedException
是由页面超时引起的。
答案 0 :(得分:0)
错误确实给了我们一些提示:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=64.0.3282.167)
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.10.0-40-generic x86_64)
一个简单的解决方案是将Key
executable_path 与 ChromeDriver 二进制文件的绝对路径的Value
一起传递,同时初始化 WebDriver 和 Web浏览器实例如下:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/usr/local/lib/python2.7/dist-packages/chromedriver_binary/chromedriver")
driver.get("http://www.google.com")
另外确保您正在使用: