Search code examples
wikipedia-apimediawiki-apiwikimedia

How to search all WikiNews articles under specific category?


I'm trying to use WikiMedia API (https://www.mediawiki.org/wiki/API:Main_page) to search all articles under specific categories (https://en.wikinews.org/wiki/Category:News_articles_by_section). For instance, find the text of all news articles under Politics and Conflicts (https://en.wikinews.org/wiki/Category:Politics_and_conflicts).

So far, I've tried the Search API function (https://www.mediawiki.org/wiki/API:Search). However, it doesn't seem to accept Deepcategory parameter.


Solution

  • You can use the CategoryMember API (https://www.mediawiki.org/wiki/API:Categorymembers).

    For instance, to list 500 recent news articles in Politics and Conflicts sorted by timestamp use the following request:

    https://en.wikinews.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Politics_and_conflicts&cmprop=ids|title|timestamp&cmsort=timestamp&cmdir=desc&cmlimit=500