爬虫代理2
import urllib.request
def ip():
thisip=urllib.request.urlopen('http://tvp.daxiangdaili.com/ip/?tid=559796713225033&num=1&foreign=only').read().decode()
print(thisip)
proxy=urllib.request.ProxyHandler({'http' : thisip})
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
for i in range(0,5):
try:
ip()
url="http://www.baidu.com"
data=urllib.request.urlopen(url).read()
print(len(data.decode()))
except Exception as err:
print(err)