3

I am looking for a wikipedia api that can give me an article (no image) to a respective query. I have seen the wikipedia api used with actions=opensearch and query=search. Please tell me which one is correct or if there is any other action I should use.

gilly3
  • 87,962
  • 25
  • 144
  • 176
shivam oberoi
  • 237
  • 4
  • 8

1 Answers1

4

See the WikiMedia API help or the complete documentation.

It's not clear what you are hoping to have returned to you, an article or search results. Either way, to get results in xml, use format=xml.

To get a listing of articles that match a certain query, use the opensearch action. For example:
http://en.wikipedia.org/w/api.php?action=opensearch&search=MediaWiki&format=xml - View the results

From the section on action=opensearch in the API help:

* action=opensearch *
  Searches the wiki using the OpenSearch protocol

This module requires read rights
Parameters:
  search     - Search string
  limit      - Maximum amount of results to return
               No more than 100 (100 for bots) allowed
               Default: 10
  namespace  - Namespaces to search
               Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                   13, 14, 15
               Maximum number of values 50 (500 for bots)
               Default: 0
  suggest    - Do nothing if $wgEnableOpenSearchSuggest is false
  format     - Output format defaults to JSON, with expanded XML optional.
               One value: json, jsonfm, xml, xmlfm
               Default: json
Example:
  api.php?action=opensearch&search=Te


To get the contents of a specific article, use the parse action. For example:
http://en.wikipedia.org/w/api.php?action=parse&page=MediaWiki&format=xml - View the results

From the section on action=parse in the API help:

* action=parse *
  Parses wikitext and returns parser output

This module requires read rights
Parameters:
  title       - Title of page the text belongs to
                Default: API
  text        - Wikitext to parse
  summary     - Summary to parse
  page        - Parse the content of this page. Cannot be used together with
                    text and title
  pageid      - Parse the content of this page. Overrides page
  redirects   - If the page or the pageid parameter is set to a redirect, resolve it
  oldid       - Parse the content of this revision. Overrides page and pageid
  prop        - Which pieces of information to get
                 text           - Gives the parsed text of the wikitext
                 langlinks      - Gives the language links in the parsed wikitext
                 categories     - Gives the categories in the parsed wikitext
                 categorieshtml - Gives the HTML version of the categories
                 languageshtml  - Gives the HTML version of the language links
                 links          - Gives the internal links in the parsed wikitext
                 templates      - Gives the templates in the parsed wikitext
                 images         - Gives the images in the parsed wikitext
                 externallinks  - Gives the external links in the parsed wikitext
                 sections       - Gives the sections in the parsed wikitext
                 revid          - Adds the revision ID of the parsed page
                 displaytitle   - Adds the title of the parsed wikitext
                 headitems      - Gives items to put in the  of the page
                 headhtml       - Gives parsed  of the page
                 iwlinks        - Gives interwiki links in the parsed wikitext
                 wikitext       - Gives the original wikitext that was parsed
                Values (separate with '|'): text, langlinks, languageshtml,
                    categories, categorieshtml, links, templates, images,
                    externallinks, sections, revid, displaytitle, headitems,
                    headhtml, iwlinks, wikitext
                Default: text|langlinks|categories|links|templates|images|
                         externallinks|sections|revid|displaytitle
  pst         - Do a pre-save transform on the input before parsing it
                Ignored if page, pageid or oldid is used
  onlypst     - Do a pre-save transform (PST) on the input, but don't parse it
                Returns the same wikitext, after a PST has been applied. Ignored if
                    page, pageid or oldid is used
  uselang     - Which language to parse the request in
  section     - Only retrieve the content of this section number
  disablepp   - Disable the PP Report from the parser output
Example:
  api.php?action=parse&text={{Project:Sandbox}}
gilly3
  • 87,962
  • 25
  • 144
  • 176
  • The OP might also want `action=query` with [`prop=revisions`](https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv), if they're interested in the raw wikitext instead of parsed HTML output. (I'm not 100% sure if that's more efficient than `action=parse` with `prop=wikitext`, but I suspect it is.) – Ilmari Karonen Jan 18 '12 at 20:50
  • u mean to say i have to use action=parse to get the result as an article.If yes can you tell me if i have to get an article on india .what all i have to do.plzzzz – shivam oberoi Jan 19 '12 at 13:44
  • 2
    @shivamoberoi - I'm not sure how much more information I can give you. If you want, I'll just write your code for you... my rate is $100/hr. – gilly3 Jan 19 '12 at 18:30
  • I got the article in XML format by using action=parse but i want to edit an article by removing all the image link and infobox ,only text to be printed.iam using java language for this. – shivam oberoi Jan 20 '12 at 10:59
  • few prop argument values like wikitext, text are not working here. http://en.wikipedia.org/w/api.php?action=query&pageids=26291&format=json&prop=wikitext but others like images etc working fine. what am i missing ? in can't find these arguments in wikipedia documentation also. – Dashrath Jul 11 '14 at 09:26
  • @Dashrath - You are using `action=query`. To get wikitext you need `action=parse`: http://en.wikipedia.org/w/api.php?action=parse&pageid=26291&format=jsonfm&prop=wikitext (I used `format=jsonfm` here so that clicking the link yields a readable result. For your code, use `format=json`.) – gilly3 Jul 11 '14 at 16:37
  • @gilly3 What does `suggest` in `opensearch` do? Can't seem to figure out... – John Strood Jul 30 '18 at 12:34