验证代理是否生效

此处介绍,购买了代理后,如何验证(动态IP)代理是否生效。

其实等价于:IP代理中的认证方式

常见的有几种。此处介绍最简单最基本的:

HTTP基本认证

另外,也从:

得知了,此处一般IP代理提供商

的认证方式,都是用的是:

Http Basic Authentication=Http基本认证

-》最通用,也相对最简单的方式

-》所以其他很多http方面的库,比如Python的requests,也才会(内置就)支持

所以只需要传递参数,无需手动自己算base64编码等过程了。

示例代码

多贝云

https://github.com/dobelgit/dobelcloud/blob/master/Python/PythonRequestsDemo.py

#! -*- encoding:utf-8 -*-

import requests

#目标网址
targetUrl = "https://www.taobao.com/help/getip.php"

#http代理接入服务器地址端口
proxyHost = "域名"
proxyPort = "端口"

#账号密码
proxyUser = "账号"
proxyPass = "密码"

proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
  "host" : proxyHost,
  "port" : proxyPort,
  "user" : proxyUser,
  "pass" : proxyPass,
}

proxies = {
  "http"  : proxyMeta,
  "https" : proxyMeta,
}

result = requests.get(targetUrl, proxies=proxies)

print result.status_code
print result.text

阿布云

https://github.com/abuyun/proxy-demo/blob/master/http-tunnel/http-dyn/python/python3/urllib/proxy-demo.py

#! -*- encoding:utf-8 -*-

import requests

# 要访问的目标页面
targetUrl = "http://test.abuyun.com"
#targetUrl = "http://proxy.abuyun.com/switch-ip"
#targetUrl = "http://proxy.abuyun.com/current-ip"

# 代理服务器
proxyHost = "http-dyn.abuyun.com"
proxyPort = "9020"

# 代理隧道验证信息
proxyUser = "H01234567890123D"
proxyPass = "0123456789012345"

proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
    "host" : proxyHost,
    "port" : proxyPort,
    "user" : proxyUser,
    "pass" : proxyPass,
}

proxies = {
    "http"  : proxyMeta,
    "https" : proxyMeta,
}

resp = requests.get(targetUrl, proxies=proxies)
print resp.status_code
print resp.text

results matching ""

    No results matching ""