我使用wikipedia api从随机页面中获取摘录。
有回复示例:
> my-project@1.0.0 transpile-views ~/Projects/my-project
> babel ./src/views --out-dir ./src/views
srcviews/AuthView.js -> src/views/AuthView.js
src/views/AuthView.jsx -> src/views/AuthView.js
src/views/HomeView.js -> src/views/HomeView.js
src/views/HomeView.jsx -> src/views/HomeView.js
src/views/MainLayout.js -> src/views/MainLayout.js
src/views/MainLayout.jsx -> src/views/MainLayout.js
现在我知道了此页面的{
"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
获取此页面的url
?
答案 0 :(得分:6)
您可以通过添加info
property和inprop=url
从API请求来获取网址。它可以与extracts
property结合使用: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>"
}
}
}
您也可以使用网址中的pageid
:https://en.wikipedia.org/?curid=864588