【发布时间】:2018-01-31 16:05:54
【问题描述】:
我试图从url 下载一个 .csv 文件,以了解股票的历史。这是我的代码:
import requests
r = requests.get("https://query1.finance.yahoo.com/v7/finance/download/CHOLAFIN.BO?period1=1514562437&period2=1517240837&interval=1d&events=history&crumb=JaCfCutLNr7")
file = open(r"history_of_stock.csv", 'w')
file.write(r.text)
file.close()
但是当我打开文件 history_of_stock.csv 时,我发现了这个:
{
"finance": {
"error": {
"code": "Unauthorized",
"description": "Invalid cookie"
}
}
}
我找不到任何可以解决我的问题的东西。我发现这个线程中有人有同样的问题,除了它在 C# 中:C# Download price data csv file from https instead of http
【问题讨论】:
标签: python-3.x csv python-requests