urllib2中使用http、https代理

来源:互联网 发布:java认证资格培训 编辑:程序博客网 时间:2024/06/09 20:59

urllib2中使用http、https代理

proxy=urllib2.ProxyHandler({'https': 'http://lk:2002@172.17.5.53:80'})
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener)

proxy=urllib2.ProxyHandler({'http': 'http://lk:2002@172.17.5.53:80'})
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener)

 

>>> urllib2.urlopen('https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=monkey&as_filetype=png&imgtype=clipart&imgc=color&rsz=8')
send: 'GET https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=monkey&as_filetype=png&imgtype=clipart&imgc=color&rsz=8 HTTP/1.1/r/nAccept-Encoding: identity/r/nHost: ajax.googleapis.com/r/nProxy-Authorization: Basic bGs6MjAwMg==/r/nConnection: close/r/nUser-Agent: Python-urllib/2.6/r/n/r/n'
reply: 'HTTP/1.0 200 OK/r/n'
header: Content-Type: text/html

header: Refresh: 0; URL=https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=monkey&as_filetype=png&imgtype=clipart&imgc=color&rsz=8

 

原创粉丝点击