What is the quickest way to HTTP GET in Python?
Python 3:
import urllib.requestcontents = urllib.request.urlopen("http://example.com/foo/bar").read()
Python 2:
import urllib2contents = urllib2.urlopen("http://example.com/foo/bar").read()
Documentation for urllib.request
and read
.
You could use a library called requests.
import requestsr = requests.get("http://example.com/foo/bar")
This is quite easy. Then you can do like this:
>>> print(r.status_code)>>> print(r.headers)>>> print(r.content)
If you want solution with httplib2 to be oneliner consider instantiating anonymous Http object
import httplib2resp, content = httplib2.Http().request("http://example.com/foo/bar")