我是初学者,所以我不明白此类错误的原因:
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)
由于您不熟悉使用 Selenium,我假设您下载了最新版本的 Selenium。尽管如此,您正在使用一段过时的代码来启动网络驱动程序。
此代码与新版本的 Selenium 中的代码类似:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
driver = webdriver.Firefox()
driver.get("http://www.python.org")
在 Selenium 文档中了解更多信息:链接