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 ===
test