对于 API 的 Python 请求,我对 URL 参数、参数和 request.get() 参数感到困惑,即使在阅读了 Python 和 API 文档之后也是如此。我只想得到带有“name”的狗:“Akita”。
以下代码适用于 5 条记录的限制,但返回的是随机的,而不仅仅是“Akita”(我知道存在)。我尝试了很多引号、大括号、字典格式、预写字符串等的排列。所有都返回没有记录、所有记录或语法失败。
response_dog = requests.get("https://api.thedogapi.com/v1/images/search?limit=5",params={'name': 'Akita'})
for current_dog in response_dog.json():
print("\n",current_dog)
输出是5条随机狗;想要的只是'name'的一只狗:'Akita'