updated wikipedia project to fix windows encoding issue
[wikipedia-api-cdsw] / wikipedia4-1.py
1 import encoding_fix
2 import requests
3
4 # ?action=query&titles=Albert%20Einstein&prop=categories
5 # Get the list of categories for the Albert Einstein article.
6
7 parameters = {'action' : 'query',
8               'titles' : 'Albert Einstein',
9               'prop' : 'categories',
10               'format' : 'json',
11               'continue' :  ''}
12
13 while True:
14     wp_call = requests.get('http://en.wikipedia.org/w/api.php', params=parameters)
15     response = wp_call.json()
16
17     for page_id in response["query"]["pages"].keys():
18         for category in response["query"]["pages"][page_id]['categories']:
19             print(category['title'])
20
21     if 'continue' in response:
22         parameters.update(response['continue'])
23     else:
24         break
25

Benjamin Mako Hill || Want to submit a patch?