這篇文章給大家分享的是有關(guān)Python代碼里面如何進行設(shè)置IP切換頭的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供日喀則網(wǎng)站建設(shè)、日喀則做網(wǎng)站、日喀則網(wǎng)站設(shè)計、日喀則網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、日喀則企業(yè)網(wǎng)站模板建站服務(wù),10年日喀則做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
requests
#! -*- encoding:utf-8 -*- import requests import random # 要訪問的目標(biāo)頁面 targetUrl = "http://httpbin.org/ip" # 要訪問的目標(biāo)HTTPS頁面 # targetUrl = "https://httpbin.org/ip" # 代理服務(wù)器 proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理隧道驗證信息 proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host" : proxyHost, "port" : proxyPort, "user" : proxyUser, "pass" : proxyPass, } # 設(shè)置 http和https訪問都是用HTTP代理 proxies = { "http" : proxyMeta, "https" : proxyMeta, } # 設(shè)置IP切換頭 tunnel = random.randint(1,10000) headers = {"Proxy-Tunnel": str(tunnel)} resp = requests.get(targetUrl, proxies=proxies, headers=headers) print resp.status_code print resp.text
感謝各位的閱讀!關(guān)于“Python代碼里面如何進行設(shè)置IP切換頭”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!