Is it possible to fetch the first few, say 1K, of a webpage using python?
Thank you very much!
Is it possible to fetch the first few, say 1K, of a webpage using python?
Thank you very much!
The Requests library lets you iterate over the response as it comes in so you could do something like this:
import requests
beginning = requests.get('http://example.com/').iter_content(1024).next()
If you just want the headers you can always use the the http HEAD method:
req = requests.head('http://example.com')
Here's an example using Python 3's urllib.request, which is built in.
import urllib.request
url = urllib.request.openurl("http://example.com").read(1024)
Sure:
>>> len(urllib2.urlopen('http://google.com').read(1024))
1024