wikipedia提供了api可以供我们对其内容进行操作。其API文档地址为:

http://en.wikipedia.org/w/api.php

列举一些常见用法:

1、全文搜索

http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=fluoxetine

srsearch为要检索的内容

结果:

  1. <?xml version="1.0"?>
  2. <api>
  3. <query>
  4. <searchinfo totalhits="224" />
  5. <search>
  6. <p ns="0" title="Fluoxetine" snippet="&lt;span class='searchmatch'&gt;Fluoxetine&lt;/span&gt; (also known by the tradenames Prozac, Sarafem) is an antidepressant  of the selective serotonin reuptake inhibitor  (SSRI) class &lt;b&gt;...&lt;/b&gt; " size="53978" wordcount="7052" timestamp="2010-10-31T23:22:00Z" />
  7. <p ns="0" title="Olanzapine/fluoxetine" snippet="The drug  combination olanzapine/&lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt; (trade name Symbyax, created by Eli Lilly and Company ) is a single capsule containing the  &lt;b&gt;...&lt;/b&gt; " size="5703" wordcount="629" timestamp="2010-09-21T09:10:34Z" />
  8. <p ns="0" title="Sertraline" snippet="Evidence suggests that sertraline may work better than &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;  (Prozac) for some subtypes of depression.  Sertraline is highly  &lt;b&gt;...&lt;/b&gt; " size="104510" wordcount="13933" timestamp="2010-10-28T22:13:04Z" />
  9. <p ns="0" title="Antidepressant" snippet="The first such compound to be patented was zimelidine  in 1971, while the first released clinically was indalpine . &lt;span class='searchmatch'&gt;Fluoxetine&lt;/span&gt;  was  &lt;b&gt;...&lt;/b&gt; " size="128712" wordcount="17532" timestamp="2010-10-30T08:05:06Z" />
  10. <p ns="0" title="Selective serotonin reuptake inhibitor" snippet="four newer antidepressants (including the SSRIs paroxetine  and &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt; , and two non-SSRI antidepressants nefazodone  and venlafaxine ).  &lt;b&gt;...&lt;/b&gt; " size="78327" wordcount="10398" timestamp="2010-11-01T00:11:30Z" />
  11. <p ns="0" title="Paroxetine" snippet="Unlike two other popular SSRI antidepressants, &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;  and sertraline , paroxetine is associated with clinically significant weight  &lt;b&gt;...&lt;/b&gt; " size="48886" wordcount="6491" timestamp="2010-10-31T23:11:12Z" />
  12. <p ns="0" title="Venlafaxine" snippet="Its efficacy is similar to or better than sertraline  (Zoloft) and &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;  (Prozac), depending on the criteria and rating scales used &lt;b&gt;...&lt;/b&gt; " size="49655" wordcount="6574" timestamp="2010-11-01T00:38:00Z" />
  13. <p ns="0" title="Olanzapine" snippet="Olanzapine (trade names Zyprexa, Zalasta, Zolafren, Olzapin, Oferta, Zypadhera or in combination with &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;  Symbyax ) is an atypical  &lt;b&gt;...&lt;/b&gt; " size="34028" wordcount="4540" timestamp="2010-10-30T17:45:42Z" />
  14. <p ns="0" title="Prozac (disambiguation)" snippet="Prozac  is a proprietary name for the antidepressant drug &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;. Prozac may also refer to:  Prozac+ , an Italian punk band &lt;b&gt;...&lt;/b&gt; " size="581" wordcount="78" timestamp="2010-04-23T20:24:31Z" />
  15. <p ns="0" title="SSRI discontinuation syndrome" snippet="paroxetine  having the highest number of withdrawal syndrome reports and &lt;span class='searchmatch'&gt;fluoxetine&lt;/span&gt;  the highest number of drug dependence reports; the note &lt;b&gt;...&lt;/b&gt; " size="41099" wordcount="5444" timestamp="2010-09-23T06:19:55Z" />
  16. </search>
  17. </query>
  18. <query-continue>
  19. <search sroffset="10" />
  20. </query-continue>
  21. </api>

2、列举wikipedia 的 category:

http://en.wikipedia.org/w/api.php?action=query&list=allcategories&acprefix=drug&aclimit=10

返回10条以drug开头的category;

结果:

  1. <?xml version="1.0"?>
  2. <api>
  3. <query>
  4. <allcategories>
  5. <c xml:space="preserve">Drug-induced Suicide</c>
  6. <c xml:space="preserve">Drug-realted suicides</c>
  7. <c xml:space="preserve">Drug-related Films</c>
  8. <c xml:space="preserve">Drug-related Suicides</c>
  9. <c xml:space="preserve">Drug-related death in California</c>
  10. <c xml:space="preserve">Drug-related deaths</c>
  11. <c xml:space="preserve">Drug-related deaths by country</c>
  12. <c xml:space="preserve">Drug-related deaths in Alabama</c>
  13. <c xml:space="preserve">Drug-related deaths in Alaska</c>
  14. <c xml:space="preserve">Drug-related deaths in Arizona</c>
  15. </allcategories>
  16. </query>
  17. <query-continue>
  18. <allcategories acfrom="Drug-related deaths in Arkansas" />
  19. </query-continue>
  20. </api>

3、返回具有相应title页面的timestamp|user|comment|content 信息;

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=api&rvprop=timestamp|user|comment|content

结果:

  1. <?xml version="1.0"?>
  2. <api>
  3. <query>
  4. <pages>
  5. <page pageid="27697087" ns="0" title="API">
  6. <revisions>
  7. <rev user="Graham87" timestamp="2010-06-13T08:41:17Z" comment="Protected API: restore protection ([edit=sysop] (indefinite) [move=sysop] (indefinite))" xml:space="preserve">#REDIRECT [[Application programming interface]]{{R from abbreviation}}</rev>
  8. </revisions>
  9. </page>
  10. </pages>
  11. </query>
  12. </api>

4、解析页面:

http://en.wikipedia.org/w/api.php?action=parse&format=xml&page=fluoxetine

用上面的查询返回的[content]是wikipedia的标记格式,这个api返回的是html格式的文本:

可以用xpath="api/parse/text" 返回html内容。

* action=parse *
  This module 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
  redirects      - If the page parameter is set to a redirect, resolve it
  oldid          - Parse the content of this revision. Overrides page
  prop           - Which pieces of information to get.
                   NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present
                   Values (separate with '|'): text, langlinks, categories, links, templates, images, externallinks, sections, revid, displaytitle, headitems, headhtml
                   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 or oldid is used.
  onlypst        - Do a PST on the input, but don't parse it.
                   Returns PSTed wikitext. Ignored if page or oldid is used.
Example:
  api.php?action=parse&text={{Project:Sandbox}}

来源:http://john2007.iteye.com/blog/800446

利用wikipedia 的API实现对其内容的查询的更多相关文章

  1. 利用百度地图API实现地址和经纬度互换查询

    import json import requests def baiduMap(input_para): headers = { 'User-Agent': 'Mozilla/5.0 (Window ...

  2. 利用百度词典API和Volley网络库开发的android词典应用

     关于百度词典API的说明,地址在这里:百度词典API介绍 关于android网络库Volley的介绍说明,地址在这里:Android网络通信库Volley 首先我们看下大体的界面布局!

  3. 利用Google Speech API实现Speech To Text

    很久很久以前, 网上流传着一个免费的,识别率暴高的,稳定的 Speech To Text API, 那就是Google Speech API. 但是最近再使用的时候,总是返回500 Error. 后来 ...

  4. 利用未公开API获取终端会话闲置时间(Idle Time)和登入时间(Logon Time)

    利用未公开API获取终端会话闲置时间(Idle Time)和登入时间(Logon Time)作者:Tuuzed(土仔)   发表于:2008年3月3日23:12:38 版权声明:可以任意转载,转载时请 ...

  5. 【百度地图API】建立全国银行位置查询系统(五)——如何更改百度地图的信息窗口内容?

    原文:[百度地图API]建立全国银行位置查询系统(五)--如何更改百度地图的信息窗口内容? 摘要: 酷讯.搜房.去哪儿网等大型房产.旅游酒店网站,用的是百度的数据库,却显示了自定义的信息窗口内容,这是 ...

  6. ASP.NET Core Web APi获取原始请求内容

    前言 我们讲过ASP.NET Core Web APi路由绑定,本节我们来讲讲如何获取客户端请求过来的内容. ASP.NET Core Web APi捕获Request.Body内容 [HttpPos ...

  7. 利用WordPress REST API 开发微信小程序从入门到放弃

    自从我发布并开源WordPress版微信小程序以来,很多WordPress网站的站长问有关程序开发的问题,其实在文章:<用微信小程序连接WordPress网站>讲述过一些基本的要点,不过仍 ...

  8. 利用百度翻译API,获取翻译结果

    利用百度翻译API,获取翻译结果 translate.py #!/usr/bin/python #-*- coding:utf-8 -*- import sys reload(sys) sys.set ...

  9. 白话SpringCloud | 第十一章:路由网关(Zuul):利用swagger2聚合API文档

    前言 通过之前的两篇文章,可以简单的搭建一个路由网关了.而我们知道,现在都奉行前后端分离开发,前后端开发的沟通成本就增加了,所以一般上我们都是通过swagger进行api文档生成的.现在由于使用了统一 ...

随机推荐

  1. 饿了么基于Vue2.0的通用组件开发之路(分享会记录)

    Element:一套通用组件库的开发之路 Element 是由饿了么UED设计.饿了么大前端开发的一套基于 Vue 2.0 的桌面端组件库.今天我们要分享的就是开发 Element 的一些心得. 官网 ...

  2. POJ2777

    http://poj.org/problem?id=2777 前几天看到一个大神说,要搞,就搞专题或者套题,我觉得现在这么菜的我,还是搞搞专题吧. 一道比较裸也比较基础的线段树的题目. 题意:就是有一 ...

  3. MySQL 日期、时间转换函数

    MySQL 日期.时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式.它是 str_to ...

  4. 一键启动NameNode和DataNode--shell脚本

    使用shell脚本,一键启动hadoop中的NameNode和DataNode.分为普通版和装逼版.装逼版较普通版多了很多判断和信息提示,当然主要还是为了我联系shell脚本而写的. 如果想实现复用, ...

  5. there's no qt version assigned to this project for platform

    VS+Qt编译一个新建的项目报there's no qt version assigned to this project for platform xxx的错误. 解决方案: 打开Qt_vs_add ...

  6. UML大战需求分析——阅读笔记05

    最近看过几个程序员大学后一起创业,与大公司抢项目并成功逆袭的视频,感触颇深:第一.技术是关键:第二.有一群可靠并且技术超群的队友,在关键时刻不会掉链子:第三.善于部署谨慎周密的计划:第四.一流的口才+ ...

  7. Delphi容器类之---Tlist,TStringlist,THashedStringlist的效率比较

    转载自:http://www.ylzx8.cn/windows/delphi/73200.html 本人在做一个测试,服务器是IOCP的,我假定最大链接数是50000个. 测试背景:如果每个链接之间的 ...

  8. Remove Duplicates from Sorted Array II

    题目简述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ...

  9. [OPENCV] 第一个程序 识别颜色

    它可以鉴别出图像中含有给定颜色的所有像素,该算法输入的是图像以及颜色,并返回表示含有指定颜色的像素的二值图像.该算法还需要指定另外一个参数,即对颜色偏差的容忍度. 实现效果 实现后 #include ...

  10. JsonHelper MergeJsonTemplate

    namespace Test { using Newtonsoft.Json; using System; using System.Collections.Generic; using System ...