我正在尝试用 Python 编写一个脚本,该脚本使用代理列表每 x 秒重新加载一个页面,而我目前遇到了一个问题。我知道这也不是代理的错,因为我可以 ping 它们并且它们返回正常。它们是 HTTP 代理。我的脚本将此错误返回给我:
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>
我不知道如何解决它。这是实际的脚本:
import urllib.request
import time
proxy_list = input("Name of proxy list file?: ")
proxy_file = open(proxy_list, 'r')
url = input("URL to bot? (Has to include http://): ")
sleep = float(input("Time between reloads? (In seconds, 0 for none): "))
proxies = []
for line in proxy_file:
proxies.append( line )
proxies = [w.replace('\n', '') for w in proxies]
while True:
for i in range(len(proxies)):
proxy = proxies[i]
proxy2 = {"http":"http://%s" % proxy}
proxy_support = urllib.request.ProxyHandler(proxy2)
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
urllib.request.urlopen(url).read()
time.sleep(float(sleep))
谢谢。