import urllib.request import random url = 'http://www.whatismyip.com' iplist = ['61.135.217.7:80','114.249.63.193:8118','114.236.44.33:61234','111.183.228.246:61234','121.232.146.65:8118'] #多搞几个ip 换着用 proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})#1参数 类型,ip,端口号 opener = urllib.request.build_opener(proxy_support)#2创建一个opener opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360EE')] urllib.request.install_opener(opener)#3安装opener response = urllib.request.urlopen(url) html = response.read().decode('utf-8') print(html)
python 代理ip
猜你喜欢
转载自blog.csdn.net/qq_41760970/article/details/80369212
今日推荐
周排行