How to get the Infobox data from Wikipedia?

20,559

Solution 1

Use the Mediawiki API through this Python library: https://github.com/siznax/wptools

Usage:

import wptools
so = wptools.page('Stack Overflow').get_parse()
infobox = so.data['infobox']
print(infobox)

Output:

{'alexa': '{{Increase}} 34 ( {{as of|2019|12|15|lc|=|y}} )',
 'author': '[[Jeff Atwood]] and [[Joel Spolsky]]',
 'caption': 'Screenshot of Stack Overflow in February 2017',
 'commercial': 'Yes',
 'content_license': '[[Creative Commons license|CC-BY-SA]] 4.0',
 'current_status': 'Online',
 'language': 'English, Spanish, Russian, Portuguese, and Japanese',
 'launch_date': '{{start date and age|2008|9|15}}',
 'logo': 'Stack Overflow logo.svg',
 'name': 'Stack Overflow',
 'owner': '[[Stack Exchange]], Inc.',
 'programming_language': '[[C Sharp (programming language)|C#]]',
 'registration': 'Optional',
 'screenshot': 'File:Stack Overflow homepage, Feb 2017.png',
 'type': '[[Knowledge market]]',
 'url': '{{URL|https://stackoverflow.com}}'}

Solution 2

If you just want to parse the infobox or you want to get some digested data, a look at the DBPedia project: http://dbpedia.org

The DBPedia project scans the infoboxes in WP to create a RDF database from Wikipedia: https://github.com/dbpedia/extraction-framework/

Solution 3

There is no trivial way to do that. You can try fetching the page content using action=raw, i.e. http://en.wikipedia.org/w/index.php?action=raw&title=Douglas_Jardine Then find the start of the infobox by searching for {{Infobox. Then find the end by finding the matching }}, taking into account that the infobox itself can also contain {{-}} and {{{-}}} pairs.

Solution 4

Each Wikipedia page is associated with a Wikidata item, and all these items include the most parameters from the Wikipedia page's Infobox templates. So you need only to access the data associated with your Wikipedia page from Wikidata API.

An example of how to get the data for Wikipedia Donald Trump page from Wikidata item:

https://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwiki&props=claims&titles=Donald Trump

The response will include: date and place of birth, image, religion, mother, father, children, height, signature, official website, etc..., all main info about Donald Trump included in the Wikipedia Infobox...

Solution 5

Tomxu - what you're talking about is a template - which is simple a page you can include on another page. For the infobox you need to start by looking at Template:Infobox. This gives you detailed instructions.

You can also press edit (or view code) and copy the contents to your own wiki. Bear in mind that templates tend to be in a hierarchy so you might need to copy other templates that Infobox uses (if you want to use them). Each template can be identified with {{}} so e.g. the Infobox template will look like this: {{Infobox}}.

I mentioned a hierarchy: you'll actually find multiple templates that all use Template: Infobox. To find them, just type this into Wikipedia's search field: Template:Infobox and then you'll find multiple examples, e.g. Template:Infobox writer

Update: if you mean Navboxes, then see this information.

Share:
20,559
tomxu
Author by

tomxu

Updated on May 18, 2020

Comments

  • tomxu
    tomxu about 4 years

    If I have the url to a page, how would I obtain the Infobox information on the right using MediaWiki webservices?

  • Le Mot Juiced
    Le Mot Juiced about 6 years
    The Template:Infobox page seems to be entirely about describing the data structure of an infobox, with no information on how to access that data on a specific page. Can you clarify how to use the information on that page?
  • Sylvain Leroux
    Sylvain Leroux about 4 years
    Wikidata is probably the way to go to extract semantic information. It seems way more robust and maintainable than parsing Wikipedia pages
  • Carter Cole
    Carter Cole over 2 years
    i used wptools ftw!