92

I'm studying the wikipedia API,

some demo api call

What is the pageid? How do I change it into a real page url?

I mean <page pageid="18630637" ns="0" title="Translation" />, how to change 18630637 into http://en.wikipedia.org/wiki/Translation?

Rich
  • 5,603
  • 9
  • 39
  • 61
yuli chika
  • 9,053
  • 20
  • 75
  • 122

3 Answers3

146

You can just use a URL like this:

http://en.wikipedia.org/?curid=18630637

This is the shortest form, others are also possible:

http://en.wikipedia.org/wiki?curid=18630637

http://en.wikipedia.org/wiki/Translation?curid=18630637

http://en.wikipedia.org/w/index.php?curid=18630637

Note that MediaWiki ignores the page title if you specify a curid, so even

http://en.wikipedia.org/wiki/FooBar?curid=18630637

leads to the same page.

  • Excellent and short this (http://en.wikipedia.org/?curid=18630637). Thanks. – netfed Oct 16 '17 at 01:07
  • Do you know if there is an option to redirect to the _title page URL_? – freezed Aug 29 '18 at 13:30
  • @freezed I don't know if there's a way using the wiki URLs, but you can get the title for a page ID from the API: https://en.wikipedia.org/w/api.php?action=query&pageids=18630637 – jcsahnwaldt Reinstate Monica Aug 29 '18 at 15:04
  • I was asking for something like when you match a _redirect page_ like this one:`https://en.wikipedia.org/w/index.php?title=Whistling_hare` redirects to `https://en.wikipedia.org/wiki/Pika`. For this pages param `redirect=no` exists (`https://en.wikipedia.org/w/index.php?title=Whistling_hare&redirect=no`). I hope for an URL like `https://en.wikipedia.org/w/index.php?curid=186307&redirect=yes`. Actually `https://en.wikipedia.org/w/index.php?curid=186307` is by default redirecting to `https://en.wikipedia.org/w/index.php?title=Pika&curid=186307` – freezed Sep 02 '18 at 10:01
  • Only don't get why http://en.wikipedia.org/?curid=18630637 loads as non-responsive on mobile device and https://en.wikipedia.org/wiki/Translation loads responsive – Jakub Dec 30 '19 at 14:58
  • How do I get JSON/XML back instead of HTML? – Abhijit Sarkar Jun 19 '20 at 00:32
84

The pageid is the MediaWiki's internal article ID. You can use the action API's info property to get the full URL from pageid:

https://en.wikipedia.org/w/api.php?action=query&prop=info&pageids=18630637&inprop=url

toto_tico
  • 17,977
  • 9
  • 97
  • 116
Matěj G.
  • 3,036
  • 1
  • 26
  • 27
  • 1
    I wrote a new answer below, maybe a comment would have been enough... You don't need two API calls, one is enough. Just add "&prop=info&inprop=url" to your original URL: http://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=meaning&srprop=size%7Cwordcount%7Ctimestamp%7Csnippet&prop=info&inprop=url – jcsahnwaldt Reinstate Monica Mar 20 '12 at 19:11
  • 1
    anyway to go the reverse? getting `pageid`/`title` from any given `url`? – Vikas Prasad Nov 29 '17 at 08:46
  • 2
    @VikasPrasad: You can use the `titles` parameter instead: `https://en.wikipedia.org/w/api.php?action=query&prop=info&titles=Stack_Overflow` – Matěj G. Nov 29 '17 at 10:10
  • 2
    @MatějG. My question is given a `url` can we get `title` or `pageid`? – Vikas Prasad Nov 29 '17 at 10:43
  • @VikasPrasad: Not for general URLs as far as I'm aware. At least not via the API. – Matěj G. Nov 29 '17 at 20:26
13

Oh, and you can also get the full page URL in your initial API call if you add "&prop=info&inprop=url":

http://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=meaning&srprop=size%7Cwordcount%7Ctimestamp%7Csnippet&prop=info&inprop=url