我是初学者,所以我不明白这种类型的错误的原因:
Traceback (most recent call last):
File "C:\Users\kerem\PycharmProjects\pythonProject\main.py", line 5, in <module>
service = Service(executable_path=ChromeDriverManager().install())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\kerem\PycharmProjects\pythonProject\venv\Lib\site-packages\webdriver_manager\chrome.py", line 40, in install
driver_path = self._get_driver_binary_path(self.driver)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\kerem\PycharmProjects\pythonProject\venv\Lib\site-packages\webdriver_manager\core\manager.py", line 40, in _get_driver_binary_path
file = self._download_manager.download_file(driver.get_driver_download_url(os_type))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\kerem\PycharmProjects\pythonProject\venv\Lib\site-packages\webdriver_manager\core\download_manager.py", line 29, in download_file
response = self._http_client.get(url)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\kerem\PycharmProjects\pythonProject\venv\Lib\site-packages\webdriver_manager\core\http.py", line 36, in get
self.validate_response(resp)
File "C:\Users\kerem\PycharmProjects\pythonProject\venv\Lib\site-packages\webdriver_manager\core\http.py", line 19, in validate_response
raise ValueError(
ValueError: response body:
Google-Edge-Cache: forbidden
Error: 7
request url:
https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/win32/chromedriver-win32.zip
response headers:
{'content-length': '37', 'content-type': 'text/plain', 'x-request-id': 'ca594d4d-aa62-4ebf-8c4c-04a30cc6a844', 'alt-svc': 'h3=":443"; ma=2592000, h3-29=":443"; ma=2592000', 'date': 'Tue, 05 Sep 2023 16:00:53 GMT', 'server': 'Google-Edge-Cache'}
Process finished with exit code 1
我试着运行这个代码
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
2条答案
按热度按时间e3bfsja21#
您使用的是最新版本的selenium,您不需要使用第三方库(如
ChromeDriverManager
)来管理浏览器驱动程序。代码可以像这样简单:参考此答案-https://stackoverflow.com/a/76463081/7598774
sbdsn5lh2#
由于您是使用Selenium的新手,我假设您下载了Selenium的最新版本。尽管如此,您正在使用一段过时的代码来启动Web驱动程序。
在新版本的Selenium中,这段代码与此类似:
阅读更多Selenium文档:链路