Polygon.io 没有在 python 中获取字典

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

我刚刚开始学习 Python,想使用 Polygon.io 探索股票价格数据。

当我访问此网址时:

https://api.polygon.io/v2/snapshot/locale/us/markets/stocks/tickers?tickers=IBM,PFE,AAPL&apiKey=secretkey

我在浏览器中取回一本字典:

{"tickers":[{"ticker":"AAPL","todaysChangePerc":-0.5598931580028782,"todaysChange":-1.0900000000000034,"updated":1703280540000000000,
"day":{"o":195.18,"h":195.375,"l":192.991,"c":193.6,"v":3.6962422e+07,"vw":194.11163},"lastQuote":{"P":198,"S":1,"p":136.44,"s":2,"t":1703278799443311062},
"lastTrade":{"i":"10271","p":193.59,"s":249,"t":1703278799420851838,"x":15},"fmv":193.555,"min":{"av":3.6962392e+07,"t":1703280480000,"n":21,"o":193.552,
"h":193.56,"l":193.552,"c":193.555,"v":793,"vw":193.55786},"prevDay":{"o":196.1,"h":197.08,"l":193.5,"c":194.68,"v":4.6482549e+07,"vw":194.7425}},
{"ticker":"PFE","todaysChangePerc":0.3532320734722763,"todaysChange":0.10000000000000142,"updated":1703280540000000000,
"day":{"o":28.44,"h":28.785,"l":28.185,"c":28.4,"v":3.4961833e+07,"vw":28.43452},"lastQuote":{"P":28.43,"S":1,"p":28.4,"s":12,"t":1703278799827072256},
"lastTrade":{"i":"56569923843421","p":28.41,"s":158,"t":1703278799010144000,"x":15},"fmv":28.385,"min":{"av":3.4961833e+07,"t":1703280480000,
"n":7,"o":28.385,"h":28.385,"l":28.385,"c":28.385,"v":271,"vw":28.385},"prevDay":{"o":27.86,"h":28.36,"l":27.78,"c":28.31,"v":5.1056623e+07,"vw":28.1783}},
{"ticker":"IBM","todaysChangePerc":0.8831944271675503,"todaysChange":1.4199999999999875,"updated":1703280540000000000,
"day":{"o":161.1,"h":162.399,"l":160.1,"c":162.14,"v":2.428677e+06,"vw":161.99941},"lastQuote":{"P":162.2,"S":2,"p":162.17,"s":2,"t":1703278796332762624},
"lastTrade":{"c":[14,41],"i":"56566754194242","p":162.2,"s":200,"t":1703278796064097792,"x":15},"fmv":161.82,"min":{"av":2.428677e+06,"t":1703280480000,
"n":19,"o":161.9,"h":161.9,"l":161.821,"c":161.821,"v":1,"vw":161.9},"prevDay":{"o":160.59,"h":161.08,"l":159.53,"c":160.78,"v":2.982924e+06,"vw":160.4584}}],
"status":"OK","request_id":"ae9740a0ac5ab53abbea64ff2e2aab3a","count":3}

我正在尝试将其返回到我的 python3 代码中,如下所示:

import requests
x = requests.get('https://api.polygon.io/v2/snapshot/locale/us/markets/stocks/tickers?tickers=IBM,PFE,AAPL&apiKey=secretkey')
print(x)

这只是打印出来我怎样才能得到x中的字典?

python-3.x dictionary url polygon.io
1个回答
0
投票

只需在url请求末尾添加.json()即可

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