gpt4 book ai didi

python - 如何从具有多个过滤器的 API 查询 JSON 数据?

转载 作者:行者123 更新时间:2023-12-01 01:06:37 27 4
gpt4 key购买 nike

我正在从 JSON API 检索数据。
数据由应用程序列表组成,每个应用程序都有许多属性。
我只想要与 query_input 匹配且不受信任的应用程序(请参阅 API 文档图片): enter image description here我想要两者的交集。我只想要符合这两个条件的应用程序。如果我使用:

parameters = {"query" : query_input, "trusted" : "false", "limit" : 3}
request = requests.get("http://(certain api link)", params = parameters)
print(json.dumps(request.json(), indent = 4))

如果我使用上面的代码,并将 query_input 设置为“facebook”,我会得到:

{
"info": {
"status": "OK",
"time": {
"seconds": 0.068413019180298,
"human": "68 milliseconds"
}
},
"datalist": {
"total": 1000,
"count": 3,
"offset": 0,
"limit": 3,
"next": 3,
"hidden": 0,
"loaded": true,
"list": [
{
"id": 44893072,
"name": "Facebook",
"package": "com.facebook.katana",
"uname": "facebook",
"size": 56986654,
"icon": "http://(certain link)",
"graphic": "http://(certain link)",
"added": "2013-02-15 03:30:51",
"modified": "2019-03-21 02:24:03",
"updated": "2019-03-21 23:01:10",
"uptype": "xxxxxxxxx",
"store": {
"id": 65518,
"name": "mark8",
"avatar": "http://(certain link)",
"appearance": {
"theme": "lightsky",
"description": ""
},
"stats": {
"apps": 3552,
"subscribers": 1110865,
"downloads": 505861392
}
},
"file": {
"vername": "215.0.0.0.37",
"vercode": 146691804,
"md5sum": "bc0ed01e35b7f888bdaa34eb2c2a2e1f",
"filesize": 56986654,
"path": "http://(certain link)",
"path_alt": "(certain link)",
"malware": {
"rank": "TRUSTED"
}
},
"stats": {
"downloads": 10272286,
"pdownloads": 122342832,
"rating": {
"avg": 4.2,
"total": 4966
},
"prating": {
"avg": 4.17,
"total": 20811
}
},
"has_versions": true,
"obb": null,
"appcoins": {
"advertising": false,
"billing": false
}
},
{
"id": 44918187,
"name": "Facebook Lite",
"package": "com.facebook.lite",
"uname": "facebook-lite",
"size": 1292422,
"icon": "http://(certain link)",
"graphic": "(certain link)",
"added": "2017-09-21 11:39:42",
"modified": "2019-03-21 19:06:13",
"updated": "2019-03-21 23:04:44",
"uptype": "xxxxxxx",
"store": {
"id": 1618942,
"name": "hazel777",
"avatar": "http://(certain link)",
"appearance": {
"theme": "pink",
"description": "Thanks 4 being a follower"
},
"stats": {
"apps": 4098,
"subscribers": 63185,
"downloads": 28170613
}
},
"file": {
"vername": "139.0.0.9.85",
"vercode": 146791354,
"md5sum": "xxxxxxxxxxxxxxxxxxxxxxxx",
"filesize": 1292422,
"path": "http://(certain link)",
"path_alt": "http://(certain link)",
"malware": {
"rank": "TRUSTED"
}
},
"stats": {
"downloads": 18393,
"pdownloads": 23956738,
"rating": {
"avg": 3,
"total": 2
},
"prating": {
"avg": 4.28,
"total": 2225
}
},
"has_versions": true,
"obb": null,
"appcoins": {
"advertising": false,
"billing": false
}
},
{
"id": 3126316,
"name": "Facebook",
"package": "com.sonyericsson.androidapp.fbsetupwizard",
"uname": "xperia-fb-setup",
"size": 181391,
"icon": "http://(certain link)",
"graphic": null,
"added": "2013-03-26 03:26:09",
"modified": "2013-05-05 17:59:53",
"updated": "2019-03-06 19:05:21",
"uptype": "dropbox",
"store": {
"id": 8655,
"name": "vitonline",
"avatar": "http://(certain link)",
"appearance": {
"theme": "light-blue",
"description": ""
},
"stats": {
"apps": 8609,
"subscribers": 27653,
"downloads": 3807977
}
},
"file": {
"vername": "5.0.A.0.10",
"vercode": 10485770,
"md5sum": "xxxxxxxxxxxxxxxx",
"filesize": 181391,
"path": "http://(certain link)",
"path_alt": "http://(certain link)",
"malware": {
"rank": "TRUSTED"
}
},
"stats": {
"downloads": 218559,
"pdownloads": 269179,
"rating": {
"avg": 3.75,
"total": 44
},
"prating": {
"avg": 3.63,
"total": 98
}
},
"has_versions": true,
"obb": null,
"appcoins": {
"advertising": false,
"billing": false
}
}
]
}
}

这确实有效。
我得到 facebook 相关的应用程序,并且因为 "limit": 3,它只显示 3 个应用程序(所有应用程序都在“datalist”>“list”中,每个应用程序以“id”开头并以“id”结尾) “账单”)。
我应该只获得恶意软件排名为“未知”的应用程序,但我却获得了恶意软件排名为“受信任”的应用程序,这是我不想要的。

最佳答案

我认为该文档有点误导。如果您将可信参数设置为 true,它将仅列出可信应用。如果您将其设置为 false,则所有应用程序均受信任且未知。

无法选择仅从来源获取未知应用程序。

我已尝试查询 Facebook,所有应用程序均返回“受信任”。也许这是因为该来源不存在不受信任/未知的应用程序。使用 terrarium 作为查询进行检查,您可以获得一些带有 trusted=false 的未知信任级别,然后在 trusted=true

时将其删除>

因此,您似乎需要手动获取所有结果,然后过滤恶意软件排名不等于“受信任”的字典

app_data = request.json()
untrusted = [app_entry for app_entry in app_data['datalist']['list'] if app_entry['file']['malware']['rank'].upper() != 'TRUSTED']

关于python - 如何从具有多个过滤器的 API 查询 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55291162/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com