Last active
May 23, 2016 17:23
-
-
Save tawateer/f87c35ef6e8b22fcdc5776199c27ae0a to your computer and use it in GitHub Desktop.
urllib2 关于 proxy 和 http version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import urllib2, httplib | |
handler=urllib2.HTTPHandler(debuglevel=1) | |
opener = urllib2.build_opener(handler) | |
urllib2.install_opener(opener) | |
url = "http://www.baidu.com" | |
print urllib2.urlopen(url).read()[:10] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/env python | |
import os | |
import urllib2, httplib | |
# 指定 proxy 之后协议会改成 1.0, 所以这两行不要也行。 | |
httplib.HTTPConnection._http_vsn = 10 | |
httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0' | |
os.environ['http_proxy'] = '52.221.229.2:8080' | |
os.environ['https_proxy'] = '52.221.229.2:8080' | |
url = "https://play.google.com/store/apps/details?hl=en&id=tr.com.fugo.kelimeavi2.en" | |
print urllib2.urlopen(url).getcode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment