关于爬虫的一点问题
import urllib.requestimport random
url = 'http://www.whatismyip.com.tw'
iplist = ['182.84.145.117:3256', '60.173.46.214:8888']
proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})
opener = urllib.request.build_opener(proxy_support)
opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')]
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print(html)
ConnectionRefusedError: 由于目标计算机积极拒绝,无法连接。
urllib.error.URLError: <urlopen error 由于目标计算机积极拒绝,无法连接。>
这是被反爬虫了嘛
免费代理几乎都不能用
页:
[1]