Revision 419505 of "API:Sandbox2" on testwiki== Sample Code ==
<div class="mw-gadget-tabbedwindow" style="width:70%">
=== Python ===
<syntaxhighlight lang="python3">
#!/usr/bin/python3
"""
get_categories.py
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"prop": "categories",
"titles": "Janelle Monáe"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items():
for cat in v['categories']:
print(cat["title"])
</syntaxhighlight>
<syntaxhighlight lang="python3">
#!/usr/bin/python3
"""
get_categories.py
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"prop": "categories",
"titles": "Janelle Monáe"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items():
for cat in v['categories']:
print(cat["title"])
</syntaxhighlight>
=== PHP ===
<poem>
asdasd
asd
as
d
as
d
as
d
as
d
as
d
</poem>
[[File:Wikipedia]]
</div>
== Sample Code ==
=== Python ===
=== PHP ===
testAll content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://test.wikipedia.org/w/index.php?oldid=419505.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|