python - 如何获得具有相同标签的帖子数量
问题描述
目前正在习惯 python 并尝试使用 stackoverflows api 来查询具有特定标签的帖子数。
import requests
BASEURL = "https://api.stackexchange.com/2.2/questions/15112125"
params = {
"site": "stackoverflow"
}
r = requests.get(BASEURL, params=params)
print(r.json())
上面的代码工作正常,但是在尝试使用/questions/tagged/python
它时无法获取有关命名标记的信息。
解决方案
似乎没有/questions/tagged
端点我认为您需要查询/questions
以获取所有问题的列表
"tags"
然后以编程方式在其标签列表( JSON 字段)中过滤它们,请参阅此处的问题格式: https ://api.stackexchange.com/docs/types/question
一个例子:
{
"tags": [
"windows",
"c#",
".net"
],
"owner": {
"reputation": 9001,
"user_id": 1,
"user_type": "registered",
"accept_rate": 55,
"profile_image": "https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?d=identicon&r=PG",
"display_name": "Example User",
"link": "https://example.stackexchange.com/users/1/example-user"
},
"is_answered": false,
"view_count": 31415,
"favorite_count": 1,
"down_vote_count": 2,
"up_vote_count": 3,
"answer_count": 0,
"score": 1,
"last_activity_date": 1549253581,
"creation_date": 1549210381,
"last_edit_date": 1549278781,
"question_id": 1234,
"link": "https://example.stackexchange.com/questions/1234/an-example-post-title",
"title": "An example post title",
"body": "An example post body"
}
还有一个端点tags/{tag}/top-askers/{period}
可以在特定标签中获取最高问题提问者,无论是在上个月还是一直。见文档
推荐阅读
- python - 任何人都知道如何编辑全局变量python?
- algorithm - 这个 n 体问题是 O(n^2) 还是 O(n log n)?
- r - 根据索引查找字符串
- c# - 服务器端点击的html按钮标签不起作用
- php - 无法在laravel gitlab ci中迁移数据库
- python-3.x - 如何在 Python 中反转一阶差分?
- python - 每次在 Kivy 中按下此特定按钮时,我都需要更改我的随机数
- angular - 用 Jasmine 模拟 Angular 9 服务
- http - 在 .Net Core 中间件中设置 Content-Range
- c - 否则如何解释它后面的 if 语句?