使用Python访问NASDAQ历史数据请求连接超时中的结果

问题描述 投票:0回答:1

[我试图运行此Python代码段(与请求库一起使用,以从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)

尽管能够通过Web浏览器访问URL并下载所需的“ .csv”文件,但是我的Python代码产生超时错误。

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))

这是因为NASDAQ.com制定了防刮擦措施,还是我的请求中缺少某些信息?任何解决此问题的帮助将不胜感激。

python python-requests finance
1个回答
0
投票

这里是使用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()

同样,请与提供者联系以获取有关正确刮取的条款。您可以查看更多硒chromewebdriver,https://chromedriver.chromium.org/getting-started

© www.soinside.com 2019 - 2024. All rights reserved.