关于python中的web抓取

2024-04-25 13:16:55 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,如果总共有5个数据点,则有两个主要变量(买入和卖出)和几个子变量(如出价、变动、时间等)。我知道如何分开做:

data[u'options'][0]["calls"][0]["change"]['fmt'], data[u'options'][0]["calls"][1]["change"]['fmt'], data[u'options'][0]["calls"][2]["change"]['fmt'], data[u'options'][0]["calls"][3]["change"]['fmt'],data[u'options'][0]["calls"][4]["change"]['fmt']

但这花了太多时间。我想知道如何在一个代码中选择多个项目。在


Tags: 数据项目代码data时间changeoptionscalls
2条回答

如果我能正确理解你的问题,你可以稍微理解一下清单。在

对于data["options"][0]["calls"]中的每个值,它将该值的[“change”][“fmt”]值添加到列表中。在

d = [call["change"]["fmt"] for call in data["options"][0]["calls"]]

如果要列出每组选项中的每个值,可以这样做:

^{pr2}$

现在你可以说

for option in d:
    for call in option:
        print(call)
[data[u'options'][0]["calls"][i]["change"]['fmt'] for i in range(5)]

我不太明白你的问题,这就是你想要的吗?在

相关问题 更多 >