我想测试列表中所包含的代理的工作状态。代理可以是HTTP/HTTPS或socks5 4/socks5 5类型,它们的格式如下:
104.207.147.141:8080
103.216.51.210:8191
3.9.34.151:3128
191.232.214.74:8080
空格4://138.59.143.37:57669
表格4://185.169.181.24:4145
表格4://45.115.112.214:40308
为了测试它们,我在http://ifconfig.me/ip站点上实现了一个请求,如果到达正确的话,它会把我的IP发回给我。:
def tester(proxies, ip, ref_IPs):
whitelist = []
for proxy in range(0, len(proxies), 1):
print(proxies[proxy])
rep = requests.get("http://ifconfig.me/ip", {'http': proxies[proxy], 'https': proxies[proxy]}, timeout=1)
if rep.text == ip:
whitelist.append(ref_IPs[proxy])
fileCreator(cleaner(whitelist, 1))整个过程都很顺利,但代理程序似乎对请求没有任何影响。因此,无论地址如何,代理都是功能性的。
191.232.214.74:8080 -> work
套接字4://138.59.143.37:57669 ->工作
AAA.k4.yy.43:B 345 ->工作
你能解释一下为什么吗?
发布于 2020-06-24 16:01:36
requests.get有以下原型:
requests.get(url, params=None, **kwargs)您需要的是kwargs中的参数“代理”,所以您的请求必须如下所示:
rep = requests.get("http://ifconfig.me/ip", proxies={'http': proxies[proxy], 'https': proxies[proxy]}, timeout=1)https://stackoverflow.com/questions/62535109
复制相似问题