I’m trying to download a CSV file from this site:
http://www.nasdaq.com/screening/companies-by-name.aspx
If I enter this URL in my Chrome browser the csv file download starts immediately, and I get a file with data on a few thousand companies. However, if I use the code below I get a access denied error. There is no login on this page, so what is the Python code doing differently?
from urllib import urlopen
response = urlopen('http://www.nasdaq.com/screening/companies-by-name.aspx?&render=download')
csv = response.read()
# Save the string to a file
csvstr = str(csv).strip("b'")
lines = csvstr.split("\\n")
f = open("C:\Users\Ankit\historical.csv", "w")
for line in lines:
f.write(line + "\n")
f.close()