Last active
March 10, 2019 05:39
-
-
Save Teraflopst/99c9c3af94ea74f12eba4991e4313153 to your computer and use it in GitHub Desktop.
Python 的几种 HTTP GET 方法
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
# 方法一: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