0

I want to download a .csv file from here automatically, every time I run the script:
https://www.nasdaq.com/market-activity/quotes/historical

So whenever I open the notebook I will get the latest data from Nasdaq, if I run the correct script, I don't have to upload the dataset manually.

This is the URL of the download: https://www.nasdaq.com/api/v1/historical/AMZN/stocks/2010-10-26/2020-10-26

I tried some libraries, but none of them worked for me. I use google colaboratory and Python3.

Kadam
  • 23
  • 1
  • 13

1 Answers1

1

For a reason which I don't understand (maybe someone here who knows more can let us both know), you need to provide headers along with your request. I got the answer from here.

So in your case the following seems to work for me:

import requests

url = 'https://www.nasdaq.com/api/v1/historical/AMZN/stocks/2010-10-26/2020-10-26'
headers = { "user-agent":"Mozilla"} 

r = requests.get(url, headers=headers)

open('HistoricalQuotes_2020_10_26.csv', 'wb').write(r.content)
kabdulla
  • 5,199
  • 3
  • 17
  • 30