mwparserfromhell.

MediaWiki Wikicodeのパーサー
今すぐダウンロード

mwparserfromhell. ランキングとまとめ

広告

  • Rating:
  • ライセンス:
  • MIT/X Consortium Lic...
  • 価格:
  • FREE
  • 出版社名:
  • Ben Kurtovic
  • 出版社のWebサイト:
  • https://github.com/earwig/

mwparserfromhell. タグ


mwparserfromhell. 説明

MWParserFromHellは、MediaWiki Wikicode用の使いやすく、不正に強力なパーサを提供するPythonパッケージです。 Python 2とPython 3。あるいは、最新の開発版を取得します。git clone git://github.com/earwig/mwparserfromhell.gitcd mwparserfromhellpython setup.py Installyouは、Python Setup.py test.usagenormalの使用法で包括的なユニットテストスイートを実行できます。 Page Text):>>>インポートMWParserFromHell >>> Wikicode = MWParserFromHell.parse(テキスト)WikicodeはMWParserFromhell.Wikicode.Wikicodeオブジェクトです。例:>>> text = "テンプレートを持っています!{{foo |バズ|バス= eggs =スパム}} ! {{fooバー| BAZ | eggs = spam}} gikicode.filter_templates()>>>プリントテンプレート >> >テンプレート=テンプレート >>> Print Template.NameFoo >>> print template.params >>> print template.get(1).valueBar >> >印刷Template.get( "Eggs")。Valuespamsinceあなたが到達するすべてのノードもWikicodeオブジェクトであることです。 ")>>> print code.filter_templates() >>> foo = code.filter_templates() >>> print foo.get(1).valuethis {{{a | template}} >>> print foo.get(1).value.filter_templates() {a |テンプレート}} >>> Print Foo。 get(1).value.filter_templates() .tget(1).valuetemplateAditionallyには、recursive = trueを渡すことによってfilter_templates()にネストされたテンプレートを含めることができます。>>> text = "{{bar} {{baz | {{spam}}}} ">>> mwparserfromhell.parse(テキスト).Filter_Templates(Recursive = True)テンプレートは簡単に追加、削除、変更することができますまたはパラメータ。 Wikicodeは、Append()、insert()、remove()、replace()などのリストのように扱うこともできます。>>> text = "{{cleanup}} '' 'foo' ''は bar]]。{{未分類}} ">>> code = mwparserfromhell.parse(テキスト)>>> code.filter_templates():... template.name ==" cleanup "とtemplate.has_paramの場合( "date"):... template.add( "date"、 "2012" ")... >>>印刷コード{{cleanup |日付= 2012年7月} '' '' foo '' 'です]。 {{未分類}} >>> code.replace( "{{bar-stub}}")>>>印刷コード{{cleanup |日付= 2012年7月} '' '' '' '' ''は]です。 {{bar-stub}} >>> print code.filter_templates()]。 {{バースタブ}} >>>テキスト== codeTrueLikewise、使用STR(コード)のPython 3.Integrationmwparserfromhell中で使用されると本来EarwigBotのために開発されています。ページオブジェクトには、PAGE.GET()でMWParSerFromHell.parse()を呼び出すPARSEメソッドがあります。Pywikipediaを使用している場合は、コードが次のようになります.PywikIbotDef ParseとしてのMWParserFromHellimport Wikipedia(タイトル):site = pywikibot.get_site ()ページ= pywikibot.Page(サイト、タイトル)テキスト= page.get()の戻りmwparserfromhell.parse(テキスト)ライブラリを使用していない場合は、次のコードを使用して任意のページにテンプレートを解析することができます(API経由):インポートjsonimport urllibimport mwparserfromhellAPI_URL =「http://en.wikipedia.org/w/api.php"def解析(タイトル):生= urllib.urlopen(API_URL、データ).read()RES = json.loads(生)テキスト= RES 。値() リターンmwparserfromhell.parse(テキスト)製品のホームページ


mwparserfromhell. 関連ソフトウェア