首页 > 解决方案 > 如何获得具有相同标签的帖子数量

问题描述

目前正在习惯 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它时无法获取有关命名标记的信息。

标签: pythonapi

解决方案


似乎没有/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}可以在特定标签中获取最高问题提问者,无论是在上个月还是一直。见文档


推荐阅读