|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import random
import json
url = 'https://ip.cn/'
req = urllib.request.Request(url)
#req.add_header('User-Agent','Test_Proxy_Python3.5_maminyao')
proxies = ['117.94.213.165:8118','119.179.136.97:8060','114.228.73.217:6666']
proxy = random.choice(proxies)
proxy_support = urllib.request.ProxyHandler({'http':proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
opener.addheaders = [('User-Agent','Test_Proxy_Python3.5_maminyao')]
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
print (json.loads(html)['ip'],json.loads(html)['country'],json.loads(html)['city'],)
#无论怎么改都是本机外网ip
因为你的 IP 是 http,而网址协议是 https
|
|