forked from wikimedia/mediawiki-api-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_info.py
More file actions
34 lines (23 loc) · 648 Bytes
/
get_info.py
File metadata and controls
34 lines (23 loc) · 648 Bytes
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
34
#This file is auto-generated. See modules.json and autogenerator.py for details
#!/usr/bin/python3
"""
get_info.py
MediaWiki API Demos
Demo of `Info` module: Send a GET request to display information about a page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"titles": "Albert Einstein",
"prop": "info",
"inprop": "url|talkid"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items():
print(v["title"] + " has " + str(v["length"]) + " bytes.")