Žádost GET/POST pro analýzu obsahu stránky a získání výstupu.
Dokumentace API
Následující dokumentace je výstupem Special:ApiHelp/parse, automaticky generovaným pre-release verzí MediaWiki, která je spuštěna na tomto webu (MediaWiki.org).
Gives parsed doctype, opening <html>, <head> element and opening <body> of the page.
modules
Gives the ResourceLoader modules used on the page. To load, use mw.loader.using(). Either jsconfigvars or encodedjsconfigvars must be requested jointly with modules.
jsconfigvars
Gives the JavaScript configuration variables specific to the page. To apply, use mw.config.set().
encodedjsconfigvars
Gives the JavaScript configuration variables specific to the page as a JSON string.
indicators
Gives the HTML of page status indicators used on the page.
iwlinks
Gives interwiki links in the parsed wikitext.
wikitext
Gives the original wikitext that was parsed.
properties
Gives various properties defined in the parsed wikitext.
limitreportdata
Gives the limit report in a structured way. Gives no data, when disablelimitreport is set.
limitreporthtml
Gives the HTML version of the limit report. Gives no data, when disablelimitreport is set.
parseroutput
Internal. Gives the JSON-serialized ParserOutput object for the parsed content. The format of this property may change at any time; mw:Manual:Parser cache/Serialization compatibility does not provide any guarantee of API stability.
parsetree
The XML parse tree of revision content (requires content model wikitext)
parsewarnings
Gives the warnings that occurred while parsing content (as wikitext).
parsewarningshtml
Gives the warnings that occurred while parsing content (as HTML).
headitems
Deprecated. prop=headitems is deprecated since MediaWiki 1.28. Use prop=headhtml when creating new HTML documents, or prop=modules|jsconfigvars when updating a document client-side.
Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with text.
Apply the selected skin to the parser output. May affect the following properties: text, langlinks, headitems, modules, jsconfigvars, indicators.
One of the following values: apioutput, authentication-popup, cologneblue, fallback, json, minerva, modern, monobook, timeless, vector, vector-2022
contentformat
Content serialization format used for the input text. Only valid when used with text.
One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
contentmodel
Content model of the input text. If omitted, title must be specified, and default will be the model of the specified title. Only valid when used with text.
One of the following values: GadgetDefinition, Graph.JsonConfig, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext, worklist
mobileformat
Return parse output in a format suitable for mobile devices.
Maximum number of values is 50 (500 for clients that are allowed higher limits).
templatesandboxtitle
Parse the page using templatesandboxtext in place of the contents of the page named here.
templatesandboxtext
Parse the page using this page content in place of the page named by templatesandboxtitle.
templatesandboxcontentmodel
Content model of templatesandboxtext.
One of the following values: GadgetDefinition, Graph.JsonConfig, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext, worklist
templatesandboxcontentformat
Content format of templatesandboxtext.
One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
#!/usr/bin/python3""" parse.py MediaWiki API Demos Demo of `Parse` module: Parse content of a page MIT License"""importrequestsS=requests.Session()URL="https://en.wikipedia.org/w/api.php"PARAMS={"action":"parse","page":"Pet door","format":"json"}R=S.get(url=URL,params=PARAMS)DATA=R.json()print(DATA["parse"]["text"]["*"])
PHP
<?php/* parse.php MediaWiki API Demos Demo of `Parse` module: Parse content of a page MIT License*/$endPoint="https://en.wikipedia.org/w/api.php";$params=["action"=>"parse","page"=>"Pet door","format"=>"json"];$url=$endPoint."?".http_build_query($params);$ch=curl_init($url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);$output=curl_exec($ch);curl_close($ch);$result=json_decode($output,true);echo($result["parse"]["text"]["*"]);
JavaScript
/** * parse.js * * MediaWiki API Demos * Demo of `Parse` module: Parse content of a page * * MIT License */consturl="https://en.wikipedia.org/w/api.php?"+newURLSearchParams({origin:"*",action:"parse",page:"Pet door",format:"json",});try{constreq=awaitfetch(url);constjson=awaitreq.json();console.log(json.parse.text["*"]);}catch(e){console.error(e);}
MediaWiki JS
/** * parse.js * * MediaWiki API Demos * Demo of `Parse` module: Parse content of a page * MIT License */constparams={action:'parse',page:'Pet door',format:'json'};constapi=newmw.Api();api.get(params).done(data=>{console.log(data.parse.text['*']);});
{"parse":{"title":"Wikipedia:Unusual articles/Places and infrastructure","pageid":38664530,"wikitext":{"*":"===Antarctica===\n<!--[[File:Grytviken church.jpg|thumb|150px|right|A little church in [[Grytviken]] in the [[Religion in Antarctica|Antarctic]].]]-->\n{| class=\"wikitable\"\n|-\n| '''[[Emilio Palma]]'''\n| An Argentine national who is the first person known to be born on the continent of Antarctica.\n|-\n| '''[[Scouting in the Antarctic]]'''\n| Always be prepared for glaciers and penguins.\n|}"}}}
Ukázkový kód
parse_wikitable.py
#!/usr/bin/python3""" parse_wikitable.py MediaWiki Action API Code Samples Demo of `Parse` module: Parse a section of a page, fetch its table data and save it to a CSV file MIT license"""importcsvimportrequestsS=requests.Session()URL="https://en.wikipedia.org/w/api.php"TITLE="Wikipedia:Unusual_articles/Places_and_infrastructure"PARAMS={'action':"parse",'page':TITLE,'prop':'wikitext','section':5,'format':"json"}defget_table():""" Parse a section of a page, fetch its table data and save it to a CSV file """res=S.get(url=URL,params=PARAMS)data=res.json()wikitext=data['parse']['wikitext']['*']lines=wikitext.split('|-')entries=[]forlineinlines:line=line.strip()ifline.startswith("|"):table=line[2:].split('||')entry=table[0].split("|")[0].strip("'''[[]]\n"),table[0].split("|")[1].strip("\n")entries.append(entry)file=open("places_and_infrastructure.csv","w")writer=csv.writer(file)writer.writerows(entries)file.close()if__name__=='__main__':get_table()
Možné chyby
Kód
Popis
missingtitle
Zadaná stránka neexistuje.
nosuchsection
stránka neobsahuje sekci section.
pagecannotexist
Menný priestor neumožňuje skutočné stránky.
invalidparammix
Parametre page, pageid, oldid, text nemožno použiť spolu.
Parametre page, pageid, oldid, title nemožno použiť spolu.
Parametre page, pageid, oldid, revid nemožno použiť spolu.