User:Euna/prototyping 14: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "= 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&<b>titl...")
 
No edit summary
 
Line 45: Line 45:


https://hub.xpub.nl/sandbot/~eunalee/__lab__/files/SI14/prototyping-times/test.html?_xsrf=2%7C27919bc0%7Ce04c1b9276a52acf4d0c8e6384264ed4%7C1610634314
https://hub.xpub.nl/sandbot/~eunalee/__lab__/files/SI14/prototyping-times/test.html?_xsrf=2%7C27919bc0%7Ce04c1b9276a52acf4d0c8e6384264ed4%7C1610634314
[[File:Capture d’écran 2021-02-05 à 18.05.31.png|thumb|imagenet1]]
[[File:Capture d’écran 2021-02-05 à 18.16.17.png|thumb|imagenet2]]

Latest revision as of 13:59, 11 February 2021

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