问题描述
是否可以在 Wikipedia API 中查询包含特定模板的文章?文档没有描述将搜索结果过滤到包含模板的页面的任何操作.具体来说,我在寻找包含 Template:Persondata
的页面.之后,我希望能够仅检索该特定模板,以便为 openancestry.org 项目填充家谱数据.
Is it possible to query the Wikipedia API for articles that contain a specific template? The documentation does not describe any action that would filter search results to pages that contain a template. Specifically, I am after pages that contain Template:Persondata
. After that, I am hoping to be able to retrieve just that specific template in order to populate genealogy data for the openancestry.org project.
下面的查询显示 Albert Einstein 页面包含 Persondata 模板,但它没有返回模板的内容,我不知道如何获取包含该模板的页面标题列表.http://en.wikipedia.org/w/api.php?action=query&prop=templates&titles=Albert%20Einstein&tlcontinue=736|10|ParmPart
The query below shows that the Albert Einstein page contains the Persondata Template, but it doesn't return the contents of the template, and I don't know how to get a list of page titles that contain the template.http://en.wikipedia.org/w/api.php?action=query&prop=templates&titles=Albert%20Einstein&tlcontinue=736|10|ParmPart
返回:
<api>
<query>
<pages>
<page pageid="736" ns="0" title="Albert Einstein">
<templates>
...
<tl ns="10" title="Template:Persondata"/>
...
</templates>
</page>
</pages>
</query>
<query-continue>
<templates tlcontinue="736|10|Reflist"/>
</query-continue>
</api>
我怀疑我无法从 API 中获得我需要的东西,但我希望我错了,而且有人已经在这条道路上开辟了道路.
I suspect that I can't get what I need from the API, but I'm hoping I'm wrong and that someone has already blazed a trail down this path.
推荐答案
您可以使用 embeddedin
查询来查找包含该模板的所有页面:
You can use the embeddedin
query to find all pages that include the template:
curl 'http://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eititle=Template:Persondata&eilimit=5&format=xml'
这让你:
<?xml version="1.0"?>
<api>
<query>
<embeddedin>
<ei pageid="307" ns="0" title="Abraham Lincoln" />
<ei pageid="308" ns="0" title="Aristotle" />
<ei pageid="339" ns="0" title="Ayn Rand" />
<ei pageid="340" ns="0" title="Alain Connes" />
<ei pageid="344" ns="0" title="Allan Dwan" />
</embeddedin>
</query>
<query-continue>
<embeddedin eicontinue="10|Persondata|595" />
</query-continue>
</api>
请参阅 mediawiki.org 上的完整文档.
See full docs at mediawiki.org.
编辑使用embeddedin
查询代替backlinks
(不包括模板包含)
Edit Use embeddedin
query instead of backlinks
(which doesn't cover template inclusions)
这篇关于维基百科 API 是否支持搜索特定模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!