Skip to content
Advertisement

Accessing NASDAQ Historical Data with Python Requests Results in Connection Timeout

I tried to run this snippet of Python code (with the requests library) to retrieve a year’s worth of Tesla’s historical market data from NASDAQ.com

dataURL = https://www.nasdaq.com/api/v1/historical/TSLA/stocks/2019-05-22/2020-05-21
quotesReq = requests.get(dataURL, allow_redirects = True)

Despite being able to access the URL through a web browser and downloading the intended “.csv” file, my Python code produces a timeout error.

requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))

Is this because NASDAQ.com has anti-scraping measures in place, or am I missing some information in my request? Any help fixing the issue would be appreciated.

Advertisement

Answer

Here is a simple solution with using Selenium chromedriver.

import time
from selenium import webdriver

dataURL = 'https://www.nasdaq.com/api/v1/historical/TSLA/stocks/2019-05-22/2020-05-21'
driver = webdriver.Chrome('C:/chromedriver.exe')  
driver.get(dataURL)
time.sleep(5)
driver.quit()

Again, check with the provider for terms on proper scraping. You can look into more of selenium chromewebdriver, https://chromedriver.chromium.org/getting-started

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement