A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

integration.rst 1.2 KiB

12345678910111213141516171819202122232425262728293031323334353637
  1. Integration
  2. ===========
  3. :mod:`mwparserfromhell` is used by and originally developed for EarwigBot_;
  4. :class:`~earwigbot.wiki.page.Page` objects have a
  5. :meth:`~earwigbot.wiki.page.Page.parse` method that essentially calls
  6. :func:`mwparserfromhell.parse() <mwparserfromhell.__init__.parse>` on
  7. :meth:`~earwigbot.wiki.page.Page.get`.
  8. If you're using Pywikipedia_, your code might look like this::
  9. import mwparserfromhell
  10. import wikipedia as pywikibot
  11. def parse(title):
  12. site = pywikibot.getSite()
  13. page = pywikibot.Page(site, title)
  14. text = page.get()
  15. return mwparserfromhell.parse(text)
  16. If you're not using a library, you can parse any page using the following code
  17. (via the API_)::
  18. import json
  19. import urllib
  20. import mwparserfromhell
  21. API_URL = "http://en.wikipedia.org/w/api.php"
  22. def parse(title):
  23. raw = urllib.urlopen(API_URL, data).read()
  24. res = json.loads(raw)
  25. text = res["query"]["pages"].values()[0]["revisions"][0]["*"]
  26. return mwparserfromhell.parse(text)
  27. .. _EarwigBot: https://github.com/earwig/earwigbot
  28. .. _Pywikipedia: https://www.mediawiki.org/wiki/Manual:Pywikipediabot
  29. .. _API: http://mediawiki.org/wiki/API