How to get the Infobox data from Wikipedia?

江枫思渺然 提交于 2019-11-27 01:44:59

Maybe a little late but i wanted the same thing and didn't see any easy solutions here, but (as Bryan points out) it turns out not to be too difficult to use the Mediawiki API with this library:

https://github.com/siznax/wptools

Usage:

>>> import wptools
>>> so = wptools.page('Stack Overflow').get_parse()
>>> so.infobox
{'alexa': '{{DecreasePositive}}',
 'author': '[[Joel Spolsky]] and [[Jeff Atwood]]',
 'caption': 'Screenshot of Stack Overflow as of February 2015',
 'commercial': 'Yes',
 'content_license': '[[Creative Commons license|CC-BY-SA]] 3.0',
 'current status': 'Online',
 'landscape': 'yes',
 'language': 'English',
 '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; Uses [[OpenID]]',
 'revenue': '',
 'screenshot': 'Stack Overflow homepage.png',
 'slogan': '',
 'type': '[[:Category:Knowledge markets|Knowledge markets]]',
 'url': '{{URL|https://stackoverflow.com}}'}
Pierre

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

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

Bryan

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.

Each Wikipedia page is associated with an 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 to your Wikipedia page from Wikidata API.

An example 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.

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.

In our project we use queries for fetching data from wiktionary like this:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fen.wiktionary.org%2Fwiki%2Flife%22%20and%20xpath%3D'%2F%2Fdiv%5B%40id%3D%22bodyContent%22%5D'&format=xml&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=recwiki

I have no comprehensive understanding of it, but it works. Output result can de filtered using jquery or something else.

What about using the Edit Mode? You could just start at the correct TextArea (most of the Time contains id="wpTextBox1") and parse the content of that TextArea ... The URL I used to find that out was (Note: section=0):

https://de.wikipedia.org/w/index.php?title=Pelephone&action=edit&section=0

Greetings

Using MediaWiki, you can view the infobox on the right of a Wikipedia page by using this link below. As you see, the format is in JSON (can be changed) and by changing the "hydrogen" word to the specific title you want you will get an page with an infobox.

https://en.wikipedia.org/w/api.php?action=parse&page=Template:Infobox%20hydrogen&format=json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!