Reputation:
Here's a Wikipedia URL:
When I navigate to it with my browser I get redirected to this URL:
But when I try to get the redirects for Ps4
using the Wikipedia API, it says that there are no redirects:
https://en.wikipedia.org/w/api.php?action=query&titles=Ps4&prop=redirects
{
"batchcomplete": "",
"query": {
"pages": {
"38596103": {
"pageid": 38596103,
"ns": 0,
"title": "Ps4"
}
}
}
}
I'm guessing that I've misunderstood the API somehow?
Upvotes: 1
Views: 81
Reputation: 9086
&prop=redirects
returns all redirects to a page, see:
https://en.wikipedia.org/w/api.php?action=query&titles=PlayStation_4&prop=redirects
To do it the other way around you should add &redirects
to your query:
https://en.wikipedia.org/w/api.php?action=query&titles=Ps4&redirects
Found the documentation at the documentation for query module:
Automatically resolve redirects in
query+titles
,query+pageids
, andquery+revids
, and in pages returned byquery+generator
.
Upvotes: 1
Reputation:
I'm not exactly sure why, but adding &redirects
to the end of the URL seems to make it return the redirects
property like I wanted:
https://en.wikipedia.org/w/api.php?action=query&titles=Ps4&prop=redirects&redirects
{
"continue": {
"rdcontinue": "38596106",
"continue": "||"
},
"query": {
"redirects": [
{
"from": "Ps4",
"to": "PlayStation 4"
}
],
"pages": {
"35723752": {
"pageid": 35723752,
"ns": 0,
"title": "PlayStation 4",
"redirects": [
{
"pageid": 5277874,
"ns": 0,
"title": "P s 4"
},
...
Upvotes: 1