啥也不說了,直接上代碼吧!
# encoding:utf-8import requests # 導(dǎo)入requests模塊用于訪問測試自己的ipimport randompro = ['1.119.129.2:8080', '115.174.66.148', '113.200.214.164'] # 在(http://www.xicidaili.com/wt/)上面收集的ip用于測試# 沒有使用字典的原因是 因?yàn)樽值渲械逆I是唯一的 http 和https 只能存在一個 所以不建議使用字典# 你的請求頭信息head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}url = 'http://www.whatismyip.com.tw/' # 你用于測試自己ip的網(wǎng)站request = requests.get(url, proxies={'http': random.choice(pro)}, headers=head) # 讓問這個網(wǎng)頁 隨機(jī)生成一個iprequest.encoding = request.apparent_encoding # 設(shè)置編碼 encoding 返回的是請求頭編碼 apparent_encoding 是從內(nèi)容網(wǎng)頁中分析出的響應(yīng)內(nèi)容編碼方式print(request.text) # 輸出返回的內(nèi)容以上這篇python3 requests中使用ip代理池隨機(jī)生成ip的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
|
新聞熱點(diǎn)
疑難解答
圖片精選