Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 510685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:08:21+00:00 2026-05-13T07:08:21+00:00

Source Mediawiki markup Right now I’m using a variety of regexes to parse the

  • 0

Source Mediawiki markup

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.

This is hardly the best method, as the number of cases that have to be made are large.

How would one parse an article’s mediawiki markup into a variety of python objects so that the data within can be used?

Example being:

  • Extract all headlines to a
    dictionary, hashing it with its
    section.
  • Grab all interwiki links, and
    stick them into a list (I know
    this can be done from the API but I’d
    rather only have one API call to
    reduce bandwidth use).
  • Extract all image names and hash them with
    their sections

A variety of regexes can achieve the above, but I’m finding the number I have to make rather large.

Here’s the mediawiki unofficial specification (I don’t find their official specification as useful).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:08:21+00:00Added an answer on May 13, 2026 at 7:08 am

    mwlib – MediaWiki parser and utility library

    pediapress/mwlib:

    mwlib provides a library for parsing MediaWiki articles and converting them to different output formats. mwlib is used by wikipedia’s “Print/export” feature in order to generate PDF documents from wikipedia articles.

    Here’s the documentation page. The older doc page used have a one-liner example:

    from mwlib.uparser import simpleparse
    simpleparse("=h1=\n*item 1\n*item2\n==h2==\nsome [[Link|caption]] there\n")
    

    If you want to see how it’s used in action, see the test cases that come with the code. (mwlib/tests/test_parser.py from git repository):

    from mwlib import parser, expander, uparser
    from mwlib.expander import DictDB
    from mwlib.xfail import xfail
    from mwlib.dummydb import DummyDB
    from mwlib.refine import util, core
    
    parse = uparser.simpleparse
    
    def test_headings():
        r=parse(u"""
    = 1 =
    == 2 ==
    = 3 =
    """)
    
        sections = [x.children[0].asText().strip() for x in r.children if isinstance(x, parser.Section)]
        assert sections == [u"1", u"3"]
    

    Also see Markup spec and Alternative parsers for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I clone my source using git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git w/ . Then I specify a
source code ... Thing is, if i specify required metadata using fluent modelmetadata provider
[Source Code] data FooBar = Foo | Bar [Command] $ ghc -c foo_bar.hs foo_bar.hs:1:0:
My source files are in this folder: c:\data\mycompany. All of my source files contain
(source: googlepages.com ) In above image I want to mark Circle's edge with red
I am trying to use HTML::WikiConverter::MediaWiki which I have installed using yum install perl-HTML-WikiConverter-MediaWiki.noarch
I'm trying to download images from specific MediaWiki pages (Or just specific images) using
Is it possible to indent a block of code in MediaWiki using SyntaxHighlight GeSHi
Source: // write Path := 'Data/_prefixed' + dynarray1[v].Name; with XMLConfig1 do begin; SetValue(Path +
Source file <?xml version=1.0 encoding=UTF-8?> <!--It will contain more data, just given few here-->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.