wikipedia-api - 通过 pageId 获取维基百科页面 url

标签 wikipedia-api mediawiki-api

我使用 wikipedia api从随机页面中获取摘录。

有示例响应:

{
    "batchcomplete": "",
    "continue": {
        "grncontinue": "0.701350797294|0.701351244349|4312122|0",
        "continue": "grncontinue||"
    },
    "query": {
        "pages": {
            "1485573": {
                "pageid": 1485573,
                "ns": 0,
                "title": "some title",
                "extract": "some text"
            }
        }
    }
}

现在我知道了这个页面的pageid

如何通过pageid获取本页的url

最佳答案

您可以通过添加 info property 从 API 请求它来获取 URL和 inprop=url。它可以与 extracts property 结合使用像这样:prop=info|extracts&inprop=url

例如:

https://en.wikipedia.org/w/api.php?action=query&generator=random&grnnamespace=0&grnlimit=2&prop=info|extracts&inprop=url

{
"continue": {
    "excontinue": 1,
    "continue": "||info"
},
"query": {
    "pages": {
        "864588": {
            "pageid": 864588,
            "ns": 0,
            "title": "Benbane Head",
            ...
            "fullurl": "https://en.wikipedia.org/wiki/Benbane_Head",
            "editurl": "https://en.wikipedia.org/w/index.php?title=Benbane_Head&action=edit",
            "canonicalurl": "https://en.wikipedia.org/wiki/Benbane_Head",
            "extract": "<p><span></span></p>\n\n<p><b>Benbane Head</b>, or <b>Benbane</b> (from Irish <i>an Bhinn Bh\u00e1n</i>, meaning \"the white headland\"), is the northernmost point of mainland Northern Ireland. It is in County Antrim, near the Giant's Causeway, which lies between Causeway Head and Benbane Head. The nearest settlements are Bushmills and Portballintrae.</p>\n<h2><span id=\"References\">References</span></h2>\n\n<p><br></p>"
        }
    }
}

您也可以只在 URL 本身中使用 pageid:https://en.wikipedia.org/?curid=864588

关于wikipedia-api - 通过 pageId 获取维基百科页面 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35323728/

相关文章:

full-text-search - 为什么标题内全文搜索返回错误

java - 如何使用 Wikipedia API 提取/解析我要查找的链接?

javascript - 在 MediaWiki 用户特定 common.js 中放入什么

wikipedia - 如何从维基百科获取搜索结果

javascript - 枚举任意对象键 - Javascript

wikipedia - 如何通过API获取Wikipedia文章的Wikidata ID?

mediawiki-api - 如何通过API在Wikimedia Commons中搜索图像?

hadoop - 从维基百科加载 30000 个文档

json - 尝试搜索维基新闻

mediawiki - 维基百科 api 全文搜索以返回带有标题、片段和图像的文章