2

I've been trying to get a list of possible results (same you would get as you perform a search in Wikipedia) and a small summary of the article, usually the first paragraph.

So far all I can get is either the list of titles:

https://en.wikipedia.org/w/api.php?action=query&origin=*&list=search&srprop&srsearch=Albert%20Einstein&prop=extracts

or the summary for a single page:

https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro=&explaintext=&titles=Albert%20Einstein

Is it possible to combine both these queries in a form similar to this

https://en.wikipedia.org/w/api.php?action=query&origin=*&list=search&srprop&srsearch=Albert%20Einstein&prop=extracts

or will I have to iterate all results from the first query and then get the extract for each one?

Termininja
  • 6,620
  • 12
  • 48
  • 49
Danyx
  • 574
  • 7
  • 34

1 Answers1

2

You can combine the results from two or more queries by using generator parameter. So the idea is to generate a list of search results (your first query) including extracts property for each one result (your second query):

action=query&generator=search&prop=extracts

Then we need to add some parameters for generator (all they prefixed with a "g")

gsrsearch=Albert%20Einstein&gsrlimit=20

and parameters for all query properties (in our case only for extracts):

exintro=1&explaintext=1&exchars=250&exlimit=20

The final query will be:

https://en.wikipedia.org/w/api.php?action=query&origin=*&generator=search&prop=extracts&gsrsearch=Albert%20Einstein&gsrlimit=20&exintro=1&explaintext=1&exchars=350&exlimit=20
Termininja
  • 6,620
  • 12
  • 48
  • 49
  • This worked perfectly! How would I go about adding a second prop (url) to the query? Simply appending &url after prop=extracts doesn't seem to work – Danyx Oct 21 '16 at 17:00
  • @Danyx to add another properties you have to separate them by pipe "|", like: `prop=categories|extracts|images|...` – Termininja Oct 21 '16 at 19:44
  • How can we get the list of all links available in the 'See Also' section? – Abhi May 02 '21 at 05:58
  • @Abhishek See [here](https://stackoverflow.com/questions/40210536/how-to-obtain-data-in-a-table-from-wikipedia-api/40388912#40388912) can to access content of some section. – Termininja May 02 '21 at 18:21