我正在寻找一个维基百科api,可以给我一篇文章(没有图片)到相应的查询。
我见过与actions=opensearch
和query=search
一起使用的维基百科api。
请告诉我哪一个是正确的,或者我应该使用其他action
。
答案 0 :(得分:4)
请参阅WikiMedia API help或complete documentation。
目前尚不清楚您希望返回给您的是什么,文章或搜索结果。无论哪种方式,要在xml中获得结果,请使用format=xml
。
要获取与特定查询匹配的文章列表,请使用opensearch
action。例如:
http://en.wikipedia.org/w/api.php?action=opensearch&search=MediaWiki&format=xml
- View the results
来自API help的action=opensearch
部分:
* 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
要获取特定文章的内容,请使用parse
action。例如:
http://en.wikipedia.org/w/api.php?action=parse&page=MediaWiki&format=xml
- View the results
来自API help的action=parse
部分:
* 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}}