0

When I make api query sometimes I have list with few pages. For example http://en.wikipedia.org/wiki/Ask gives a lot of pages, I need website "Ask.com, a web search engine, formerly Ask Jeeves" can I make query only for some category ("websites")? How I can check category for each page in response? Thanks

svick
  • 236,525
  • 50
  • 385
  • 514

3 Answers3

1

There is no trivial way to do what you're asking. You could do something like this:

  1. Get the list of pages the disambiguation page list. You could do this by listing the links on that page (action=query&prop=links).
  2. Get the categories of all the pages from the previous step and use that to decide which one is the one you're looking for. This is not that simple, because Ask.com is not directly in Category:Websites, it's in one of its subcategories.
svick
  • 236,525
  • 50
  • 385
  • 514
1

I have list with few pages, for example http://en.wikipedia.org/wiki/Ask

The problem is that you're not getting a list of pages, you just are getting an ordinary page which is in the disambiguation pages category. To get the list, you need to get the links in that page.

can I make query only for some category ("websites")?

No, mediawiki does not support that.

How I can check category for each page in response?

Use the links property as a title list generator and get the categories of each page in the response. In your case, that would be http://en.wikipedia.org/w/api.php?action=query&titles=Ask&generator=links&prop=categories (don't forget to continue the query).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

If you are OK with "full-text search" for "ask", you can do that like this:

http://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrsearch=ask%20incategory:%22Online%20companies%22&prop=info

As you can see, "search" text is [ask incategory:"Online companies"]

The same solution also can be seen at: Wikipedia API: how to search for a term in a specific category

Community
  • 1
  • 1
toshi
  • 2,757
  • 1
  • 16
  • 12