The easiest way, if you don't want to parse the wiki markup yourself, is to retrieve the parsed HTML version of the page and then process it using an HTML parser (like jsoup, as recommended by Hasham).
Besides just scraping the normal wiki user interface (which will give you the page HTML wrapped in the navigation skin), there are two ways of getting the HTML text of a MediaWiki page:
use the API with
action=parse
, which will return the page HTML wrapped in a MediaWiki API XML (or JSON / YAML / etc.) response, like this:or use the main
index.php
script withaction=render
, which will return just the page HTML:
Ps. Since you mention sections in your question, let me note that the action=parse
API module can return information about the sections on the page using prop=sections
(or even prop=sections|text
). For an example, see this API query: