python - 无法建立新连接最大重试错误

标签 python selenium selenium-webdriver

我正在尝试在 Google Chrome 上使用 Selenium 为网络抓取工具创建脚本。但是我收到错误:

raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', >port=53051): Max retries exceeded with url: >/session/54df0082f43bf3d90fa9623057c3cf53/elements (Caused by >NewConnectionError(': Failed to establish a new connection: [Errno 61] Connection refused',))

这是我迄今为止关于使用 selenium 和 webdriver 的代码。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

# Specifying incognito mode as you launch your browser[OPTIONAL]
option = webdriver.ChromeOptions()
option.add_argument("--incognito")

# Create new Instance of Chrome in incognito mode
browser = webdriver.Chrome(executable_path='/Users/emmanuelyamoah/Downloads/chromedriver-2', chrome_options=option)

# Go to desired website
browser.get("https://github.com/sonyemman")

# Wait 20 seconds for page to load
timeout = 20
try:
    # Wait until the final element [Avatar link] is loaded.
    # Assumption: If Avatar link is loaded, the whole page would be relatively loaded because it is among
    # the last things to be loaded.
    WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, "//img[@class='avatar width-full rounded-2']")))
except TimeoutException:
    print("Timed out waiting for page to load")
    browser.quit()

最佳答案

这不是您的代码错误,而是您在该网站上制作了太多的问题,我强烈建议您使用this ,因为它将确保对网站的每个请求都来自不同的计算机。

关于python - 无法建立新连接最大重试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107886/

相关文章:

python /PyQt4 : How do you find the SIZE of a monitor (in inches)?

python - 在循环中按类名查找元素,selenium

Python - 如何使用正则表达式分割字符串但保留包含分割分隔符的模式?

java - 是否可以将定位器从属性文件传递到 POM 中的 @FindBy 注释?

python - 如何正确使用 find_element_by_link_text() 不引发 NoSuchElementException?

python - 用cython将c++代码编译成pyd

java - Web 应用程序测试中的完整字段从 Python/Eclipse/DyDev 中的映射文档调用数据

java - Web 驱动程序和 Web 驱动程序后端 Selenium 和 PhantomJs 之间的区别

ruby - 在没有 RSpec 的情况下使用 Capybara live

Python 和 Selenium - 在不关闭浏览器的情况下关闭所有选项卡