image - How to download files over HTTP via python-urllib2 correctly? -
i've written parser on python download images internet:
import urllib2 in xrange(1,10): r = urllib2.urlopen('http://example.com/'+str(i)+'.gif')) f = open('c:\\' + str(i) + '.gif', 'w+') f.write(r.read()) f.close()
images can't opened. windows says 'error while building image'. i've found every line of received file less on 1 byte line of original file, both similar. how download correct file?
when working windows may need put "binary" flag b
in open...
f = open(r'c:\\'+str(i)+'.gif','wb')
Comments
Post a Comment