首页 > 代码库 > python代理可用检测、代理类型检测

python代理可用检测、代理类型检测

#coding:utf-8
import urllib2

def url_user_agent(proxy,url):
    proxy_support = urllib2.ProxyHandler({‘http‘:proxy})
    opener = urllib2.build_opener(proxy_support)
    urllib2.install_opener(opener)
    i_headers = {‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48‘}
    req = urllib2.Request(url,headers=i_headers)
    html = urllib2.urlopen(req,timeout=2)
    if url == html.geturl():
        doc = html.read()
        return doc
    return

for x in ["IP:port","IP:port"]
    print x
    try:
        url = ‘http://httpbin.org/get?show_env=1‘
        doc = url_user_agent(x ,url)
        print doc
        print ‘---‘
    except Exception, e:
        print e

  

python代理可用检测、代理类型检测