3

I'm looking for a way to get info from wikipedia based on the page title.

example: If i have a page called "Britney Spears" i want to be able to get a simple bio extracted from wikipedia onto the page. "age" "height" that sort of stuff.

  • Wikidata is for that: Britney Spears on Wikidata They're interlinked, wikipedia points to the wikidata entry (look for the link Wikidata item on the left) and wikidata points to the different wikipedia articles about B. Spears (scroll to the bottom of the B. Spears page on Wikidata), so that should be an easy task. – marfi Jan 26 '17 at 6:57
2

From Wikidata API, you could access the data from Britney Spears entity using the wbgetentities endpoint: https://www.wikidata.org/w/api.php?action=wbgetentities&titles=Britney%20Spears&sites=enwiki&format=json&props=claims

Then, to access data as age or height, you will need to understand a bit of how properties and claims work in Wikidata: height will be P2048, age will need to be calculated from date of birth P569, etc.

If you happen to work in JS, you can use wikidata-sdk to parse those claims data to something simpler to work with

2

For bios, you can also use the Wikipedia Open Search API, which is more simple than Wikidata :

https://en.wikipedia.org/w/api.php?action=opensearch&search=britney+spears&limit=10&namespace=0&format=xml

(you could also ask "format=json" instead of xml, but the output will be strangely formated and difficult to parse)

With a software like Open Refine, you could automate the search for a column of page names, like this :

Here is a demo.

Once the xml extracted, you can parse the descriptions from it with this GREL formula :

value.parseHtml().select('Description').htmlText()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.