#从雅虎财经网站上爬取数据
import time
from urllib.request import urlretrieve
assets = ["GM","AAPL","KO"]
start_date = '2019-12-30'
end_date = '2020-01-03'
start_array = time.strptime(start_date,"%Y-%m-%d") #将字符串格式化
start_stamp = int(time.mktime(start_array)) #将格式化的datetime转换成时间戳
end_array = time.strptime(end_date,"%Y-%m-%d")
end_stamp = int(time.mktime(end_array))
print(start_stamp,end_stamp)
start=str(start_stamp)
end=str(end_stamp)
print(start,end)
#循环爬取数据
for asset in assets:
url = 'https://query1.finance.yahoo.com/v7/finance/download/'+ asset + '?period1='+ start +'&period2='+ end + '&interval=1d&events=history'
filename = asset + '.csv'
urlretrieve (url, filename)
time.sleep(1)
转载自原文链接, 如需删除请联系管理员。
原文链接:爬取雅虎财经网数据,转载请注明来源!