Skip to content

Instantly share code, notes, and snippets.

@Teraflopst
Last active March 10, 2019 05:39
Show Gist options
  • Save Teraflopst/99c9c3af94ea74f12eba4991e4313153 to your computer and use it in GitHub Desktop.
Save Teraflopst/99c9c3af94ea74f12eba4991e4313153 to your computer and use it in GitHub Desktop.
Python 的几种 HTTP GET 方法
# 方法一:Python 2.x:
import urllib2
contents = urllib2.urlopen("http://example.com/foo/bar").read()
# 方法二:Python 3.x:
import urllib.request
contents = urllib.request.urlopen("http://example.com/foo/bar").read()
# 方法三:需要安装requests
import requests
r = requests.get("http://example.com/foo/bar")
print(r.status_code)
print(r.headers)
print(r.content)
# 来源:https://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment