基于来自Stack Exchange数据浏览器(SEDE)的查询:
select Tags.TagName, Count(Tags.TagName) as TagCount from Posts
join PostTags on Posts.Id = PostTags.PostID
join Tags on PostTags.TagID = Tags.ID
where Posts.Tags like '%<keras>%'
group by Tags.TagName
order by TagCount desc
有一个名为PostTags
的表,其中包含帖子中的标签。
通过使用Stack Exchange API,我可以获得帖子。 但是如何在帖子中获取标签?
答案 0 :(得分:2)
问题尚不清楚。但是,如果您要在the Stack Exchange API中重复该SEDE查询,请知道这是可能的,但并非那么简单。未为临时数据摘要设置该API。
要获得keras问题中存在的标签的摘要,您还必须:
keras
。那就是177个API 页面,或您日常API配额的很大一部分。keras
的问题。此功能齐全的演示说明了过程(但限制为2页结果,以避免耗尽演示的配额)
var srchTag = "keras";
const cYourKey = ""; // "&key=3TIJXXXXXXXXXXXXXZB0AA(("; // key is optional but very recommended
const cMaxPages = 2; // WARNING: Only set this higher once you are sure the code is as you want it.
var tagStats = {};
getPageOfQuestions (1);
function getPageOfQuestions (pageNum) {
fetch (
`https://api.stackexchange.com/2.2/questions?tagged=${srchTag}&page=${pageNum}&pagesize=100&sort=creation&order=asc&site=stackoverflow&filter=!-W2eZY)NCj(NnIzhnVP6${cYourKey}`
)
.then (function (response) {
if (response.ok) return response.json();
throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
} )
.then (function (rJsn) {
if (rJsn.backoff || rJsn.error_id) {
throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
}
console.log (`Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`);
let allDone = ! rJsn.has_more;
let zQuestions = rJsn.items;
for (let qstn of zQuestions) {
for (let zTag of qstn.tags) {
let tagStat = (tagStats[zTag] || 0) + 1;
tagStats[zTag] = tagStat;
}
}
if (rJsn.has_more) {
let newPageNm = rJsn.page + 1;
if (newPageNm <= cMaxPages)
getPageOfQuestions (newPageNm);
else
allDone = true;
}
if (allDone) {
//--- Do final processing here...
console.log ("IMPORTANT: Due to current limitations of Stack Overflow Snippets, only the 1st 40 lines are displayed."); // prod code won't need that limit.
let J = 1;
let tagsByPop = Object.keys (tagStats).sort ( (a, b) => (tagStats[b] - tagStats[a]) );
for (let zTag of tagsByPop) {
console.log ( (zTag + ":").padEnd(35), tagStats[zTag]); // 35 is max tagName length.
if (J++ >= 40) break;
}
}
} );
};
.as-console-wrapper { max-height: 100% !important; top: 0; }