小编Nem*_*nem的帖子

如何在 Stack Exchange API 中使用自定义过滤器?

我正在尝试从 StackApi 获取问题和答案来训练深度学习模型。我有一个问题,我不明白如何使用自定义过滤器,所以我只能得到问题的正文。

\n

这是我的代码:

\n
from stackapi import StackAPI\nimport torch\nimport torch.nn as nn\n\nSITE = StackAPI('stackoverflow')\nSITE.max_pages=1\nSITE.page_size=1\ndata = SITE.fetch('questions', tagged='python',filter = '!*SU8CGYZitCB.D*(BDVIficKj7nFMLLDij64nVID)N9aK3GmR9kT4IzT*5iO_1y3iZ)6W.G*', sort = 'votes')\nfor quest in data['items']:\n    question = quest['title']\n    print(question)\n    question_id = quest['question_id']\n    print (question_id)\n    dataAnswer = SITE.fetch('questions/{ids}/answers', ids=[question_id], filter='withbody')\n    print(dataAnswer)\n
Run Code Online (Sandbox Code Playgroud)\n

我的 dataAnswer 结果:

\n
{'backoff': 0, 'has_more': True, 'page': 1, 'quota_max': 300, 'quota_remaining': 300, 'total': 0, 'items': [{'owner': {'reputation': 404, 'user_id': 11182732, 'user_type': 'registered', 'profile_image': 'https://lh6.googleusercontent.com/-F2a9OP4yGHc/AAAAAAAAAAI/AAAAAAAADVo/Mn4oVgim-m8/photo.jpg?sz=128', 'display_name': 'Aditya patil', 'link': '/sf/users/782791271/'}, 'is_accepted': False, 'score': 8, 'last_activity_date': 1609856797, …
Run Code Online (Sandbox Code Playgroud)

python stackexchange-api

3
推荐指数
1
解决办法
1186
查看次数

标签 统计

python ×1

stackexchange-api ×1