@
kendetrics 请教应该怎么设置代理
def __init__(self):
self.proxylist = ('120.195.199.251:80',
'110.73.7.198:8123')
self.proxies = {'':random.choice(self.proxylist)}
self.user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
self.headers = { 'User-Agent' : self.user_agent }
def contentlist(self,url):
proxy = urllib.request.ProxyHandler(self.proxies)
opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
request = urllib.request.Request(url=url, headers=self.headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
return content
我这样写有什么错误,不管怎么换 ip,结果还是 403