我在使用 selenium 中未检测到的 chrome 浏览器打开 chrome 浏览器时收到 HTTP 404 错误。 有一天代码运行良好,突然停止工作,我尝试重新安装 unDetected_chromedriver 和 selenium,但它不起作用。
这是我在 jupyter 笔记本中使用的部分代码
[Cell 1]
import undetected_chromedriver as uc
from undetected_chromedriver import ChromeOptions
[Cell 2]
chrome_options = ChromeOptions()
# options.add_argument("--headless")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-notifications")
driver = uc.Chrome(options=chrome_options)
driver.maximize_window()
wait = WebDriverWait(driver, 60)
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Cell In[3], line 10
7 chrome_options.add_argument("--disable-notifications")
8 chrome_options.add_argument("--incognito")
---> 10 driver = uc.Chrome(options=chrome_options)
11 driver.maximize_window()
12 wait = WebDriverWait(driver, 60)
File d:\venv\lib\site-packages\undetected_chromedriver\__init__.py:258, in Chrome.__init__(self, options, user_data_dir, driver_executable_path, browser_executable_path, port, enable_cdp_events, desired_capabilities, advanced_elements, keep_alive, log_level, headless, version_main, patcher_force_close, suppress_welcome, use_subprocess, debug, no_sandbox, user_multi_procs, **kw)
251 self.patcher = Patcher(
252 executable_path=driver_executable_path,
253 force=patcher_force_close,
254 version_main=version_main,
255 user_multi_procs=user_multi_procs,
256 )
257 # self.patcher.auto(user_multiprocess = user_multi_num_procs)
--> 258 self.patcher.auto()
260 # self.patcher = patcher
261 if not options:
File d:\venv\lib\site-packages\undetected_chromedriver\patcher.py:178, in Patcher.auto(self, executable_path, force, version_main, _)
176 self.version_main = release.version[0]
177 self.version_full = release
--> 178 self.unzip_package(self.fetch_package())
179 return self.patch()
File d:\venv\lib\site-packages\undetected_chromedriver\patcher.py:287, in Patcher.fetch_package(self)
284 download_url %= (self.version_full.vstring, self.platform_name, zip_name)
286 logger.debug("downloading from %s" % download_url)
--> 287 return urlretrieve(download_url)[0]
File C:\Program Files\Python38\lib\urllib\request.py:247, in urlretrieve(url, filename, reporthook, data)
230 """
231 Retrieve a URL into a temporary location on disk.
232
(...)
243 data file as well as the resulting HTTPMessage object.
244 """
245 url_type, path = _splittype(url)
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
250 # Just return the local path and the "headers" for file://
251 # URLs. No sense in performing a copy unless requested.
File C:\Program Files\Python38\lib\urllib\request.py:222, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
File C:\Program Files\Python38\lib\urllib\request.py:531, in OpenerDirector.open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
533 return response
File C:\Program Files\Python38\lib\urllib\request.py:640, in HTTPErrorProcessor.http_response(self, request, response)
637 # According to RFC 2616, "2xx" code indicates that the client's
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
643 return response
File C:\Program Files\Python38\lib\urllib\request.py:569, in OpenerDirector.error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
File C:\Program Files\Python38\lib\urllib\request.py:502, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
File C:\Program Files\Python38\lib\urllib\request.py:649, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found
我尝试重新安装 undected_chromedriver 和 selenium,但不起作用
我遇到了类似的问题,并通过更改 patcher.py 中的行(在您的情况下位于 d:env\lib\site-packages\unDetected_chromedriver\patcher.py)中临时修复了它,这要归功于 this 评论。来自
download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/%s/%s/%s"
到
download_url = "https://storage.googleapis.com/chrome-for-testing-public/%s/%s/%s"