X-Git-Url: https://projects.mako.cc/source/wikipedia-api-cdsw/blobdiff_plain/f17f0a3f63dd03d70cdc693da0bda53a1e85671b..99337ede51f8abbcf0663e7c93672f70f9b6ddd9:/wikipedia4.py diff --git a/wikipedia4.py b/wikipedia4.py new file mode 100644 index 0000000..1798d1a --- /dev/null +++ b/wikipedia4.py @@ -0,0 +1,24 @@ +import requests + +# ?action=query&titles=Albert%20Einstein&prop=categories +# Get the list of categories for the Albert Einstein article. + +parameters = {'action' : 'query', + 'titles' : 'Albert Einstein', + 'prop' : 'categories', + 'format' : 'json', + 'continue' : ''} + +while True: + wp_call = requests.get('http://en.wikipedia.org/w/api.php', params=parameters) + response = wp_call.json() + + for page_id in response["query"]["pages"].keys(): + for category in response["query"]["pages"][page_id]['categories']: + print(category['title']) + + if 'continue' in response: + parameters.update(response['continue']) + else: + break +