2 # -*- coding: iso-8859-1 -*-
10 ## Callback function invoked when progress information is updated
11 def progress(download_t, download_d, upload_t, upload_d):
12 print "Total to download %d bytes, have %d bytes so far" % \
13 (download_t, download_d)
15 url = "http://www.cnn.com"
17 print "Starting downloading", url
19 f = open("body", "wb")
20 h = open("header", "wb")
23 c.setopt(c.WRITEDATA, f)
24 c.setopt(c.NOPROGRESS, 0)
25 c.setopt(c.PROGRESSFUNCTION, progress)
26 c.setopt(c.FOLLOWLOCATION, 1)
27 c.setopt(c.MAXREDIRS, 5)
28 c.setopt(c.WRITEHEADER, h)
29 c.setopt(c.OPT_FILETIME, 1)
33 print "HTTP-code:", c.getinfo(c.HTTP_CODE)
34 print "Total-time:", c.getinfo(c.TOTAL_TIME)
35 print "Download speed: %.2f bytes/second" % c.getinfo(c.SPEED_DOWNLOAD)
36 print "Document size: %d bytes" % c.getinfo(c.SIZE_DOWNLOAD)
37 print "Effective URL:", c.getinfo(c.EFFECTIVE_URL)
38 print "Content-type:", c.getinfo(c.CONTENT_TYPE)
39 print "Namelookup-time:", c.getinfo(c.NAMELOOKUP_TIME)
40 print "Redirect-time:", c.getinfo(c.REDIRECT_TIME)
41 print "Redirect-count:", c.getinfo(c.REDIRECT_COUNT)
42 epoch = c.getinfo(c.INFO_FILETIME)
43 print "Filetime: %d (%s)" % (epoch, time.ctime(epoch))
45 print "Header is in file 'header', body is in file 'body'"