Python uses proxy IP to access Web sites

Source: Internet
Author: User
#-*-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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.