|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import random
url = 'http://www.whatismyip.com.tw'
iplist = ['119.6.144.73:81','49.70.89.62:9999','60.167.20.198:1133','58.253.156.212:9999','36.251.147.43:9999']
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/78.0.3904.108 Safari/537.36']
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print(html)
Traceback (most recent call last):
File "F:\python练习\poxy_eg.py", line 15, in <module>
response = urllib.request.urlopen(url)
File "E:\python\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "E:\python\lib\urllib\request.py", line 514, in open
req = meth(req)
File "E:\python\lib\urllib\request.py", line 1294, in do_request_
for name, value in self.parent.addheaders:
ValueError: too many values to unpack (expected 2)
这个台湾网站,在内地你打不开,另外你使用的几个代理ip都是免费代理ip吧,都超时没作用。
|
|