python使用代理ip訪問網站

來源:互聯網
上載者:User
# -*- coding: UTF-8 -*-from urllib import requestif __name__ == "__main__":    #訪問網址    url = 'http://www.whatismyip.com.tw/'    #這是代理IP    ip = '27.155.101.233:3128'    #設定代理ip訪問方式,http和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是一個查詢ip的網站,上面代碼我使用了27.155.101.233,連接埠號碼是3128對這個網站進行訪問

這是輸出資訊:


可以看到已經使用了27.155.101.233這個代理ip對whatismyip進行訪問,但是沒有做到高匿,被這個網站查出了真實ip。

但是應對大部分投票之類的事,還是沒有問題的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.