User:Euna/prototyping 14

From XPUB & Lens-Based wiki
< User:Euna
Revision as of 12:59, 11 February 2021 by Euna (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Wiki API

API

Application Programming Interface. Get info from A (site, app) and export to B

possible to get in query and parse

query : /api.php?action=query&titles=Category:Situationist_Times&format=json

parse : /api.php?action=query&page=Category:Situationist_Times&format=json

Read and Write with API

to read a content;

import urllib
import json

request = urllib.request.urlopen(url).read()
data = json.loads(request)

data

to write a content;

test = "hello"
out = open('test.html', 'w')
out.write(test)
out.close()

#or for writing an exported html content

data = html
out = open('test.html', 'w')
out.write(html)
out.close()

In json form, possible to choose a specific result with []

# data result : {'parse': {'title': ......
data = html[parse][title] #gives only the title value

https://hub.xpub.nl/sandbot/~eunalee/__lab__/files/SI14/prototyping-times/test.html?_xsrf=2%7C27919bc0%7Ce04c1b9276a52acf4d0c8e6384264ed4%7C1610634314

imagenet1
imagenet2