Python 为什么chrome webdriver配置无效?
我正在尝试使用Selenium驱动程序运行刮板 我的py文件刚刚开始Python 为什么chrome webdriver配置无效?,python,selenium,google-chrome,selenium-chromedriver,Python,Selenium,Google Chrome,Selenium Chromedriver,我正在尝试使用Selenium驱动程序运行刮板 我的py文件刚刚开始 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException # Set the url we want <an
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
# Set the url we want
<and so on>
但是,我得到以下错误:
Traceback (most recent call last):
File "main.py", line 37, in <module>
driver = webdriver.Chrome(chrome_options=options)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, 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_respons
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming has crashed.)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.4.0-140-generic
搜索这个错误,它似乎在ChromeDriver和Google Chrome以及Selenium中不兼容,但是我的Selenium版本是3.141.0,我的Chrome版本是72.0.3626.119,我的ChromeDriver是2.46
所以它们都是最新的,而且看起来都是兼容的
有什么问题吗?我在Ubuntu 18.04上遇到了这个错误,这可能是导致Chrome崩溃的原因之一。尝试设置以下标志:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
-headless标志确保Chrome以headless模式启动,因为我假设你的Ubuntu上没有运行桌面。在Linux中,-no sandbox标志关闭沙箱,有时会在开始时导致问题。我在Ubuntu 18.04上遇到了这个错误,这可能是导致Chrome崩溃的原因之一。尝试设置以下标志:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
-headless标志确保Chrome以headless模式启动,因为我假设你的Ubuntu上没有运行桌面。-no sandbox标志关闭Linux中的沙箱,有时会在开始时导致问题。是否每次都会发生此错误?您尝试过几次重新运行测试吗?是的,尝试过几次,但都出现了相同的错误。您可以尝试自己运行chromedriver吗?请看一下:您是否指定了chrome驱动器的路径?是否每次都会出现此错误?你试过几次重新运行测试吗?是的,试过几次,但都是相同的错误。你能试着自己运行chromedriver吗?看看这个:你指定了chrome驱动程序的路径了吗