我通过以下代码下载了历史股票数据。
url = "https://query1.finance.yahoo.com/v7/finance/download/RELIANCE.BO?period1=1577110559&period2=1608732959&interval=1d&events=history&includeAdjustedClose=true"
r = requests.get(url)
然后我尝试csv
通过此代码将其写入文件。
open('ril.csv').write(r.content)
但它给出了一个错误提示
TypeError: write() argument must be str, not bytes
修改后的代码:
url = "https://query1.finance.yahoo.com/v7/finance/download/RELIANCE.BO?period1=1577110559&period2=1608732959&interval=1d&events=history&includeAdjustedClose=true"
r = requests.get(url)
open('ril.csv','wb').write(r.content)
数据是以二进制形式下载的,所以我们也需要以二进制形式对其进行读写。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句