Introduction
text and pictures of this article from the network, only to learn, exchange, not for any commercial purposes, belongs to original author, if any questions, please contact us for treatment.
How do you know if python proxy ip masquerading success when reptiles:
Sometimes our crawler to add a proxy, but we do not know the program is to get the ip, especially dynamic forwarding mode, this time on the need for testing, and the following is a proxy masquerading whether successful detection method, using here Recommend the sample code provided one hundred million cattle cloud.
PS: If necessary crawlers Python fans + data analysis learning materials can click on the link below to obtain their own
http://note.youdao.com/noteshare?id=a3a533247e4c084a72c9ae88c271e3d1
Python¶
requests
#! -*- encoding:utf-8 -*-
import requests
import random
# 要访问的目标页面
targetUrl = "http://httpbin.org/ip"
# 要访问的目标HTTPS页面
# targetUrl = "https://httpbin.org/ip"
# 代理服务器
proxyHost = "t.16yun.cn"
proxyPort = "31111"
# 代理隧道验证信息
proxyUser = "16ZKBRLB"
proxyPass = "234076"
proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
"host" : proxyHost,
"port" : proxyPort,
"user" : proxyUser,
"pass" : proxyPass,
}
# 设置 http和https访问都是用HTTP代理
proxies = {
"http" : proxyMeta,
"https" : proxyMeta,
}
# 设置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
To detect whether agent to obtain, direct access http://httpbin.org/ip site After configuring the proxy, ip and then get access to www.ip138.com know whether to get the ip.