How to get wiki template's content?

倾然丶 夕夏残阳落幕 提交于 2020-03-18 12:50:26

问题


Does anybody know how to get access to the template's body inside the page?

I'm familiar with the API that returns the list of ALL templates that exist on the page, but how I can get access to the template's body? Is there any API for this? For now I see only one possible way... parse it manually. Am I wrong?


回答1:


You can use the expandtemplates API call, or the rvexpandtemplates parameter for the revisions API call.




回答2:


This is an old question, but it helped me figure out how to fetch a mediawiki page with template macros expanded. Very useful if you are doing a conversion.

<MW_BASEURL>/api.php?action=query&prop=revisions
   &titles=<url_encoded_page_title>&format=xml&rvprop=content&rvexpandtemplates

I am parsing the xml returned from this query to get the expanded page.



来源:https://stackoverflow.com/questions/7416776/how-to-get-wiki-templates-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!