title: How to parse/extract data from a mediawiki marked-up article via python
body: <p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Foobar&amp;redirects&amp;rvprop=content&amp;format=xml" rel="noreferrer">Source Mediawiki markup</a></p>
  
  <p>Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the article can be used. </p>
  
  <p>This is hardly the best method, as the number of cases that have to be made are large.</p>
  
  <p>How would one parse an article's mediawiki markup into a variety of python objects so that the data within can be used?</p>
  
  <p>Example being: </p>
  
  <ul>
  <li>Extract all headlines to a
  dictionary, hashing it with its
  section. </li>
  <li>Grab all interwiki links, and
  stick them into a list (I know<br>
  this can be done from the API but I'd
  rather only have one API call to<br>
  reduce bandwidth use).</li>
  <li>Extract all image names and hash them with
  their sections</li>
  </ul>
  
  <p>A variety of regexes can achieve the above, but I'm finding the number I have to make rather large.</p>
  
  <p>Here's the <a href="http://www.mediawiki.org/wiki/Help:Formatting" rel="noreferrer">mediawiki unofficial specification</a> (I don't find their official <a href="http://www.mediawiki.org/wiki/Markup_spec" rel="noreferrer">specification</a> as useful).</p>