马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 游戏小虾米 于 2017-8-27 20:05 编辑
Tip:
一,理论
二,应用
1import urllib.request
import random
url = 'http://www.whatismyip.com.tw'
ipList = ['116.19.96.131:9797','111.155.116.233:8123','111.155.116.200:8123']
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 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')]
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print(html)
结果无法访问,可能原因是www.whatismyip.com.tw无法访问,直接网页访问也打不开,只能在百度快照里看一下
三,课后练习 |