Last active
June 24, 2023 21:05
-
-
Save morrisalp/8fb89b43d79e2ea2190b18441e83d5eb to your computer and use it in GitHub Desktop.
Get all page names in a given Wiktionary category (e.g. "English lemmas") using the Wiki REST API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def pages_in_wiktionary_category(category_name, language = 'en'): | |
| cont = '' | |
| while True: | |
| url = f'https://{language}.wiktionary.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:{category_name}&cmlimit=500&format=json&cmcontinue={cont}' | |
| obj = requests.get(url).json() | |
| for x in obj['query']['categorymembers']: yield x['title'] | |
| if 'continue' not in obj: break | |
| cont = obj['continue']['cmcontinue'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment