我正在尝试在 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/