簡體   English   中英

如何將非常量變量插入到 json url 中

[英]How to insert a non-constant variable into a json url

對不起,標題難以理解,希望我能澄清一下。 代碼的第一部分工作正常,但現在我想將所有“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)

我想從之前獲取的列表中獲取第二個參數“配置文件”。

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

我收到了一大堆錯誤,我什至不知道從哪里開始解決這個問題。 如果需要,我會澄清。 提前致謝,再次對任何混淆表示歉意。

此類 url 的末尾沒有額外的" ,因此更改

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM