#coding: utf8
#使用 requests ,python 2.3 皆可用 ,推荐!
import requests
resp = requests.get('https://www.alipay.com/',
proxies=dict(http='http://122.96.59.106:80' # http : 协议:IP地址
))
print(resp.status_code)
#利用urllib的 request 适用于py3
from urllib import request
proxy_support = request.ProxyHandler({'http': 'http://122.96.59.106:80'})
opener = request.build_opener(proxy_support, request.HTTPHandler)
request.install_opener(opener)
cont= request.urlopen('http://www.baidu.com/').read()
print(cont)
# python2 中 调用requesocks
import requesocks as requests
session = requests.session()
session.proxies = {'http': 'socks5://127.0.0.1:8087',
'https': 'socks5://127.0.0.1:8087'}
resp = session.get('https://www.facebook.com/', auth=('myEmail', 'psw'))
print(resp.text)
#py2中调用 urllib2,
import urllib2
req = urllib2.Request('http://www.baidu.com/')
req.set_proxy(proxy, proxy_type)
response = urllib2.urlopen(req)
print response
网友评论