Last active
December 12, 2015 09:07
-
-
Save ischurov/1568b0debac15f51bd4a to your computer and use it in GitHub Desktop.
Get all page titles for pages in some category in Wikipedia (presently, names of all personalias are requested from ruwiki)
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 | |
url = "https://ru.wikipedia.org/w/api.php" | |
query = {'action':'query', | |
'list':'categorymembers', | |
'cmtitle':'Категория: Персоналии по алфавиту', | |
'cmstartsortkeyprefix':'А', | |
'format':'json', | |
'cmlimit':500 | |
} | |
names = [] | |
for p in range(10): | |
data = requests.get(url,query).json() | |
for page in data['query']['categorymembers']: | |
names.append(page['title']) | |
print(page['title']) | |
if 'continue' in data: | |
query.update(data['continue']) | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment