Question

I am trying to parse response from the Wikipedia API (MediaWiki). The URL i am using are of the form -

https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Argo_(2012_film)

Response from the api has the wikipedia content inside a xml tag which looks like : (this is just an incomplete sample)

{{Use mdy dates|date=October 2012}} {{Infobox film | name = Argo | image = 
Argo2012Poster.jpg | alt = <!-- See: WP:ALT --> | caption = Theatrical release poster | 
tagline = "The movie was fake. The mission was real." | director = [[Ben Affleck]] | 
producer = [[Grant Heslov]]<br />Ben Affleck<br />[[George Clooney]] | based on = {{Based 
on|''The Master of Disguise''|[[Tony Mendez|Antonio J. Mendez]]}}<br />{{Based on|''The 
Great Escape''|[[Joshuah Bearman]]}} | screenplay = [[Chris Terrio]] | starring = Ben 
Affleck<br />[[Bryan Cranston]]<br />[[Alan Arkin]]<br />[[John Goodman]] | music = 
[[Alexandre Desplat]] | cinematography = [[Rodrigo Prieto]] | editing = [[William 
Goldenberg]] | studio = [[Graham King|GK Films]]<br />[[Smokehouse Pictures]] | distributor = 
[[Warner Bros.]] | released = {{Film date|2012|08|31|Telluride Film 
Festival|2012|10|12|United States}} | runtime = 120 minutes<ref> ...continued

This does not look like JSON or XML, how do i parse this?

Was it helpful?

Solution

If you want to get the content parsed as HTML, add &rvparse to the query.

For example when you execute the query

https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Argo_%282012_film%29&rvparse

the response contains something like (after skipping the infobox):

<i><b>Argo</b></i> is a 2012 American <a href="/wiki/Political_thriller"
title="Political thriller">political thriller</a> film directed by <a
href="/wiki/Ben_Affleck" title="Ben Affleck">Ben Affleck</a>.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top