通过pageId获取维基百科页面网址

Ale*_*ndr 0 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"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

我怎么能得到url这个页面pageid

sla*_*rte 7

您可以通过添加info属性和API从API请求来获取URL inprop=url.它可以与这样的extracts属性结合: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>"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您也可以使用pageidURL本身:https://en.wikipedia.org/ ?curid = 864588