by ez77 · 15y ago · 0 comments
import requests
r = requests.get('http://gun.io')
print r.content
That's it! In only three lines of python, you can grab a whole webpage and print it to the screen. Awesome!Well, that's a poor selling point that unduly diminishes the credibility of the article. Your audience is likely to know snappy alternatives such as
curl gun.io import urllib
foo = urllib.urlopen("http://gun.io).read()
print foo
I mean...maybe urllib (or urllib2) are old and unhip at this point, but they're heavily documented.I use urllib all over my projects and have never encountered any problems.
import requests
print requests.get('http://gun.io').content
Only two lines! import urllib
print urllib.urlopen('http://gun.io').read()
And to be clear, you'd really never want to just print the content like that. You'd be doing something like. import urllib
import simplejson
req = urllib.urlopen("https://graph.facebook.com/some_id")
response = req.read()
json_data = simplejson.loads(response)
(Python is syntactically pretty, imho) import requests; print requests.get('http://gun.io').content
my god, python is cloud scale. print __import__('requests').get('http://gun.io').content