【发布时间】:2025-12-22 15:55:06
【问题描述】:
对于 API 的 Python 请求,我对 URL 参数、参数和 request.get() 参数感到困惑,即使在阅读了 Python 和 API 文档之后也是如此。我只想得到带有“名字”的狗:“秋田”。
以下代码适用于 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 条随机狗;想要的只是“名字”的一只狗:“秋田”
【问题讨论】:
标签: python filter parameters request arguments