【问题标题】:Cannot connect to chrome at 127.0.0.1:53007 while using undetected_chromedriver in Python在 Python 中使用 undetected_chromedriver 时无法在 127.0.0.1:53007 连接到 chrome
【发布时间】:2022-07-31 02:23:54
【问题描述】:

我正在尝试使用 undetected_chromedriver 绕过 Cloudfare 保护。

这是我尝试使用的简单代码

import undetected_chromedriver as uc
from selenium import webdriver
import time

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")

driver = uc.Chrome(options=options)

url = 'https://etherscan.io/tx/0x6b0e974952c7df4270cfb4aac332042af9b72c487e42d0bc04a676134118c1ac'

driver.get(url)
time.sleep(5)
print(driver.title)

但是,我得到了错误:

Traceback (most recent call last):
  File "test2.py", line 9, in <module>
    driver = uc.Chrome(options=options)
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 401, in __init__
    super(Chrome, self).__init__(
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in __init__
    self.start_session(capabilities, browser_profile)
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 589, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 425, in execute
    self.error_handler.check_response(response)
  File "/root/tx_sniper/my_env/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:58911
from chrome not reachable
Stacktrace:
#0 0x5622d155aad3 <unknown>
#1 0x5622d12ba3ff <unknown>
#2 0x5622d12a8ab9 <unknown>
#3 0x5622d12e0f69 <unknown>
#4 0x5622d12d8ee6 <unknown>
#5 0x5622d13142ba <unknown>
#6 0x5622d130e4e3 <unknown>
#7 0x5622d12e3d1a <unknown>
#8 0x5622d12e4e75 <unknown>
#9 0x5622d1588efd <unknown>
#10 0x5622d15a219b <unknown>
#11 0x5622d158ac65 <unknown>
#12 0x5622d15a2ec8 <unknown>
#13 0x5622d157e360 <unknown>
#14 0x5622d15bea68 <unknown>
#15 0x5622d15bebe8 <unknown>
#16 0x5622d15d87fd <unknown>
#17 0x7f129a6566db <unknown>

我正在使用以下版本:

Python 3.8

谷歌浏览器:100.0.4896.75

Chrome 驱动程序:100.0.4896.60

未检测到的chromedriver:3.1.5.post4

硒:4.1.3

【问题讨论】:

  • 硒版?
  • 始终将完整的错误消息(从单词“Traceback”开始)作为文本(不是屏幕截图,不是指向外部门户的链接)(不是在 cmets 中)。还有其他有用的信息。
  • 当然,我现在就去做。谢谢推荐
  • @undetectedSelenium selenium==4.1.3
  • @furas 我再次编辑了我的问题。

标签: python selenium undetected-chromedriver


【解决方案1】:

通常我使用chrome的默认userdata-dir,例如:/home/vncuser/.config/google-chrome

我有时也会遇到同样的问题,我需要做的只是删除 userdata-dir 中的首选项文件:

rm ~/.config/google-chrome/Default/Preferences

如果“首选项”文件太大(1~3 GB),chrome 会崩溃。该文件的正常大小只有几个 KB。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,同时测试了一些新的网址来抓取..
    一切顺利,直到突然我得到错误:

        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:58911
    from chrome not reachable
    Stacktrace: blablabla
    

    按照何志空的建议做了:
    我的个人资料文件夹大约 3 gig,所以我删除了我的个人资料文件夹,它又像魅力一样运行了 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-23
      • 2021-12-30
      • 2022-07-18
      • 1970-01-01
      • 2014-08-28
      • 2020-09-29
      • 2018-04-29
      • 1970-01-01
      相关资源
      最近更新 更多