-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwikipedia2-2.py
More file actions
33 lines (25 loc) · 1.1 KB
/
wikipedia2-2.py
File metadata and controls
33 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import encoding_fix
import requests
# base url:
# https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=%s&rvlimit=100&rvprop=timestamp|user&format=json
pages = ["Benjamin Mako Hill", "University of Washington", "Data science"]
parameters = {'action' : 'query',
'prop' : 'revisions',
'rvlimit' : 100,
'rvprop' : 'timestamp|user',
'format' : 'json',
'continue' : ''}
for page_title in pages:
parameters['titles'] = page_title
while True:
wp_call = requests.get('https://en.wikipedia.org/w/api.php', params=parameters)
response = wp_call.json()
for page_id in response["query"]["pages"].keys():
page_title = response["query"]["pages"][page_id]["title"]
revisions = response["query"]["pages"][page_id]["revisions"]
for rev in revisions:
print(page_title + "\t" + rev["user"] + "\t" + rev["timestamp"])
if 'continue' in response:
parameters.update(response['continue'])
else:
break