end0tknr's kipple - 新web写経開発

http://d.hatena.ne.jp/end0tknr/ から移転しました

urllib.request for python における proxy 経由での http get

import urllib.request as req

proxy = req.ProxyHandler({'http': r'$user_id:$user_pw@proxy_host:80'})
auth = req.HTTPBasicAuthHandler()
opener = req.build_opener(proxy, auth, req.HTTPHandler)
req.install_opener(opener)
conn = req.urlopen('https://www.yahoo.co.jp')
return_str = conn.read()
print( return_str )