【发布时间】:2021-08-07 12:09:15
【问题描述】:
有如下代码
import requests
# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
url = 'https://www.alphavantage.co/query?function=EMA&symbol=IBM&interval=weekly&time_period=10&series_type=open&apikey=demo'
r = requests.get(url)
data = r.json()
print(data)
我正在寻找的是如何通过请求嵌入股票代码而不总是更改 URL 代码。像一开始的样子
stock = input("Please enter a ticker symbol")
在此示例中,stock 在 URL 中等于 IBM
我想过这样的方法,但不幸的是它不起作用。结果我得到了“{}”。有什么想法吗?
import requests
# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
stock = input("Please enter a ticker symbol")
url= f"https://www.alphavantage.co/query?function=EMA&symbol={'stock'}&interval=weekly&time_period=10&series_type=open&apikey=MYAPI"
r = requests.get(url)
data = r.json()
print(data)
PS 如果您有任何更好的网络经济数据,我很感谢您的任何建议。
【问题讨论】:
-
经济数据请查看:github.com/ranaroussi/yfinance
标签: python python-3.x request stock