API:Get the contents of a page

From mediawiki.org
Jump to navigation Jump to search
Other languages:
Deutsch • ‎English • ‎Türkçe • ‎español • ‎français • ‎polski • ‎русский • ‎中文 • ‎日本語 • ‎한국어

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

  1. Get the contents of a page using the Revisions API (as wikitext).
  2. Get the contents of a page using the Parse API (as HTML or wikitext).
  3. Get plain text or limited HTML extracts of a page using the API of the TextExtracts extension.

Method 1: Use the Revisions API[edit]

The Revisions API can be used to retrieve the content of a page as wikitext. This can be done by specifying the title of the page in the titles parameter and setting the rvprop parameter to content. For more options, see API:Revisions .

Example[edit]

GET request to obtain the wikitext content of the page Pet door.

Response[edit]

Method 2: Use the Parse API[edit]

The Parse API can be used to retrieve page content in either HTML format (parsed) or Wikitext format (unparsed). This can be done by specifying a page with the page parameter or a revision with the oldid parameter. To retrieve HTML, set prop to text. To retrieve Wikitext, set prop to wikitext.

Example 1[edit]

GET request to get parsed HTML content of a page: Pet door

Response[edit]

Example 2[edit]

GET request to get the original wikitext content of a page: Pet door

Response[edit]

Method 3: Use the TextExtracts API[edit]

Note that the TextExtracts extension must be installed on the wiki in order to use this method. To see if it is installed, go to Special:Version on the wiki you are targeting.

The TextExtracts extension provides an API which allows you to retrieve plain-text or limited HTML extracts of page content. See Extension:TextExtracts for additional documentation.

Example[edit]

Get request to extract 10 sentences from the page w:Pet door.

Response[edit]

Additional notes[edit]

The content extracted directly from Wikipedia can be inserted into any MediaWiki wiki through Extension:InterwikiExtracts . The content extracted comes in the form of limited wikitext, omitting leading templates, links to files or pages.

See also[edit]