Does the Wikipedia API support searches for a specific template?

限于喜欢 提交于 2019-11-30 08:43:27

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'

Which gets you:

<?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>

See full docs at mediawiki.org.

Edit Use embeddedin query instead of backlinks (which doesn't cover template inclusions)

user2419708

Using embeddedin does not allow you to search for a specific person, the search string becomes the Template:Persondata.

The best way I've found to get only people from Wikipedia is to use list=search and filter the search using AND"Born"AND"Occupation":

http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch="Tom Cruise"AND"Born"AND"Occupation"&format=jsonfm&srprop=snippet&srlimit=50`

Remember that Wikipedia is using a search engine that doesn't yet allow us to search only the title, it will search the full text. You can take advantage of that to get more precise results.

The accepted answer explains how to list pages using a certain template, but if you need to search for pages using the template, you can with the hastemplate: search keyword: https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=hastemplate:NPOV%20physics

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