#-*-Coding:utf-8-*-from
urllib Import Request
If __name__ = "__main__":
#访问网址
url = ' Http://www.what ismyip.com.tw/'
#这是代理IP
ip = ' 27.155.101.233:3128 '
#设置代理ip访问方式, HTTP and https
proxy = {' http ': IP, ' HTTPS ': IP}
#创建ProxyHandler
proxy_support = Request. Proxyhandler (proxy)
#创建Opener
opener = Request.build_opener (proxy_support)
#添加User angent
Opener.addheaders = [(' User-agent ', ' mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.221 safari/537.36 SE 2.X METASR 1.0 ')]
#安装OPener
request.install_opener (opener)
#使用自己安装好的Opener
response = request.urlopen (URL)
#读取相应信息并解码
html = Response.read (). Decode ("Utf-8")
#打印信息
print (HTML)
Whatismyip is a query IP site, the above code I used 27.155.101.233, the port number is 3128 access to this site
This is the output information:
Can see already used 27.155.101.233 this proxy IP to Whatismyip to visit, but did not do high hide, was this website to detect the real IP.
But it's not a problem to deal with most votes or something.