I\'m trying to download a CSV file from this site, but I keep getting an HTML file when I\'m using this piece of code (which used to work until a few weeks ago), or when I\'m us
Solved by using the Requests library instead of urllib2:
import requests
url = "http://www.....aspx?download=1"
file_name = "Data.csv"
u = requests.get(url)
file_size = int(u.headers['content-length'])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
with open(file_name, 'wb') as f:
for chunk in u.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
f.close()