【问题标题】:How to insert a non-constant variable into a json url如何将非常量变量插入 json url
【发布时间】:2020-11-18 00:15:59
【问题描述】:

抱歉标题难以理解,希望我能澄清一下。第一部分代码工作正常,但现在我想将所有“uuid”插入请求中,并在 for 循环中从每个请求中获取一些东西,也许。

import requests
import json

uuids = []
count = 0
catacombs = []

data = requests.get("https://api.hypixel.net/guild?key=42d64fe9-677c-433b-9460-f0177e0b9ded&id=5f1654598ea8c918612a6a43").json()
for guild in data["guild"]["members"]:
    uuids.append(guild["uuid"])

而不是这个...

data = requests.get("https://api.hypixel.net/skyblock/profile?key=42d64fe9-677c-433b-9460-f0177e0b9ded&profile=0baac74f903143e49d24015d8bc3a733").json()
print(data)

我想像这样从先前获取的列表中获取第二个参数“profile”。

data = requests.get("\"https://api.hypixel.net/skyblock/profile?key=42d64fe9-677c-433b-9460-f0177e0b9ded&profile=" + str(uuids[count]) + "\"").json()
print(data)

我遇到了一大堆错误,我什至不知道从哪里开始解决这个问题。如果需要,我会澄清。在此先感谢您,再次对任何混淆表示歉意。

【问题讨论】:

    标签: python json api web-scraping


    【解决方案1】:

    这些网址的末尾没有多余的",所以改变

    data = requests.get("\"https://api.hypixel.net/skyblock/profile?key=42d64fe9-677c-433b-9460-f0177e0b9ded&profile=" + str(uuids[count]) + "\"").json()
    

    data = requests.get("https://api.hypixel.net/skyblock/profile?key=42d64fe9-677c-433b-9460-f0177e0b9ded&profile=" + str(uuids[count])).json()
    

    【讨论】:

      猜你喜欢
      • 2012-04-19
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 2015-11-08
      • 1970-01-01
      相关资源
      最近更新 更多