【问题标题】:Max retries exceeded with url: / Caused by ProxyErrorurl 超出最大重试次数:/ 由 ProxyError 引起
【发布时间】:2020-05-14 16:53:28
【问题描述】:

我想从这个网页获取一些代理列表; https://free-proxy-list.net/ 但我陷入了这个错误,不知道如何解决它。

requests.exceptions.ProxyError: HTTPSConnectionPool(host='free-proxy-list.net', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x00000278BFFA1EB0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected 
party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))

顺便说一句,这是我的相关代码:

import urllib
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
ua = UserAgent(cache=False)
header = {
    "User-Agent": str(ua.msie)
    }
proxy = {
    "https": "http://95.66.151.101:8080"
}
urls = "https://free-proxy-list.net/"
res = requests.get(urls, proxies=proxy)
soup = BeautifulSoup(res.text,'lxml')

我尝试抓取其他网站,但我意识到不是这样。

【问题讨论】:

    标签: python web-scraping beautifulsoup python-requests


    【解决方案1】:

    当您的代理是 http 代理时,您在 Json dict 中使用 https

    代理应始终采用这种格式

    对于 http 代理

    {'"http": "Http Proxy"}
    

    对于 https 代理

    {"https":"Https Proxy"}
    

    对于用户代理

    {"User-Agent": "Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.2.15 Version/10.00"}
    

    示例

    import requests
    requests.get("https://example.com", proxies={"http":"http://95.66.151.101:8080"}, headers={"User-Agent": "Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.2.15 Version/10.00"})
    

    你导入的模块from fake_useragent import UserAgent是无关紧要的,没有必要

    额外

    也可能因为代理无效或响应不正确而发生错误

    如果您正在寻找免费的代理列表,请考虑查看这些来源

    https://pastebin.com/raw/VJwVkqRT

    https://proxyscrape.com/free-proxy-list

    https://www.freeproxylists.net/

    【讨论】:

      【解决方案2】:

      我从未见过fake_useragent 模块,也不知道它的用途,但我删除了它。也不知道您为什么添加这些标题元素,但我认为您描述的任务没有必要。查看链接中的 html,代理位于 section id="list"--&gt;div class="container"--&gt; &lt;tbody&gt;。下面的代码确实提供了上述区域中的所有元素,并包括所有代理。如果您想获得更具体的信息,可以更改此设置。

      import requests
      from bs4 import BeautifulSoup
      
      urls = "https://free-proxy-list.net/"
      res = requests.get(urls)
      soup = BeautifulSoup(res.text,"html.parser")
      
      
      tbody = soup.find("tbody")
      
      print(tbody.prettify())
      

      【讨论】:

      • 完全相同的错误?这对我有用,所以这很奇怪
      • 您是否配置了无法访问的代理?
      • 不。我什么也没做。我认为它与我的 IP 地址有关,你知道吗?
      • 即使使用正确的代理,您的代码也无法运行。我发布的代码应该可以工作。我的代码不起作用表明您的代理配置错误 (ProxyError)。我没有关于您的设置的信息,所以我无法进一步帮助您。不过,我怀疑它对您的 IP 的影响。
      • 我发现了问题所在,这个网站 (free-proxy-list.net) 在我们国家(伊朗)是过滤器,我设置的代理 proxy = { "https": "http://95.66.151.101:8080" } 也不能正常工作,所以我必须寻找另一个代理:D,感谢您的时间伙伴。
      猜你喜欢
      • 2016-10-12
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 2013-08-30
      • 2021-02-03
      相关资源
      最近更新 更多