User:User:Dikshagupta99/Sandbox/API:Get the contents of a page

There are basically three main methods for retrieving page contents via the API:


 * 1) Get data about the set of pages by setting titles or page ids(for retrieving wikitext)
 * 2) Specify content explicitely using text, title, revid and content model(for retrieving parsed content)
 * 3) Return plain text or limited HTML extracts of a given page.

Method 1: Get revised page data from API:Revisions
There are several ways of getting the revised data:


 * 1) Get data about a set of pages (last revision), by setting titles or pageids.
 * 2) Get revisions for one given page, by using titles or pageids with start, end, or limit.
 * 3) Get data about a set of revisions by setting their IDs with revids.

Example 1
The below GET request is to obtain revised data of the page.

Response
}}\n\n==Possible Errors==\n\n* \'\'\'readapidenied\'\'\' – You need read permission to use this module.\n\n\n\n\n'}}, 'comment': 'translation tweaks'}, {'user': 'Shirayuki', 'timestamp': '2018-11-04T13:27:38Z', 'slots': {'main': {'contentmodel': 'wikitext', 'contentformat': 'text/x-wiki', 'content': '\n\n\nExport an RSD schema.\n\n==Parameters==\n\nNone\n\n==Example==\n\n\n\n==Possible Errors==\n\n* \'\'\'readapidenied\'\'\' – \n\n\n\n\n'}}, 'comment': 'use Template:int'}, {'user': 'Shirayuki', 'timestamp': '2018-11-04T13:28:53Z', 'slots': {'main': {'contentmodel': 'wikitext', 'contentformat': 'text/x-wiki', 'content': ' \n\n\n\nExport an RSD schema.\n\n==Parameters==\n\nNone\n\n==Example==\n\n\n\n\n==Possible Errors==\n\n* \'\'\'readapidenied\'\'\' – \n\n\n\n\n'}}, 'comment': 'prepare for translation'}, {'user': 'Shirayuki', 'timestamp': '2018-11-04T13:29:00Z', 'slots': {'main': {'contentmodel': 'wikitext', 'contentformat': 'text/x-wiki', 'content': ' \n\n\n\n\nExport an RSD schema.\n\n==Parameters== \n\n\nNone\n\n==Example== \n\n\n\n\n==Possible Errors==\n\n* \'\'\'readapidenied\'\'\' – \n\n\n\n\n'}}, 'comment': 'Marked this version for translation'}, {'user': 'Shirayuki', 'timestamp': '2018-11-04T13:33:18Z', 'slots': {'main': {'contentmodel': 'wikitext', 'contentformat': 'text/x-wiki', 'content': ' \n\n\n\n\nExport an RSD schema.\n\n==Parameters== \n\n\nNone\n\n==Example== \n\n\n\n\n==Possible Errors==\n\n* \'\'\'readapidenied\'\'\' – \n\n\n\n'}}, 'comment': 'cat'} }

For the sample codes, view

Method 2: Get the content of a page by API:Parsing_wikitext
There are several ways to specify the text to parse:


 * 1) Specify a page or revision, using page, pageid, or oldid.
 * 2) Specify content explicitly, using text, title, revid, and contentmodel.
 * 3) Specify only a summary to parse. prop should be given an empty value.

For more details regarding API:Parsing_wikitext view

Example
GET request to get parsed content of a page:Main_page

Method 3: Get the content of the page using Extension:TextExtracts#API
The TextExtracts extension provides an API which allows to retrieve plain-text or limited HTML extracts of page content.

Example
Get a 100-character extract:

Download Extension
To download extension view-