有没有办法通过维基百科API返回标题链接?

时间:2014-04-20 17:29:15

标签: json wikipedia-api

我使用http://en.wikipedia.org/w/api.phpformat=json&action=query&list=search|allpages&srsearch=wikipedia json结果是

{
   "query-continue":{
      "allpages":{
         "apcontinue":"!!Fuck_you!!"
      },
      "search":{
         "sroffset":10
      }
   },
   "query":{
      "searchinfo":{
         "totalhits":71955
      },
      "search":[
         {
            "ns":0,
            "title":"Wikipedia",
            "snippet":"<span class='searchmatch'>Wikipedia</span>. (audio En-uk-<span class='searchmatch'>Wikipedia</span>. ogg | \u02cc | w | \u026a | k | \u0268 | \u02c8 | p | i\u02d0 | d | i | \u0259 or. audio en-us-<span class='searchmatch'>Wikipedia</span>. ogg | \u02cc | w | \u026a | k | i | \u02c8 | p |  <b>...</b> ",
            "size":201609,
            "wordcount":26085,
            "timestamp":"2014-04-17T17:46:32Z"
         },
         {
            "ns":0,
            "title":"Wikip\u00e9dia",
            "snippet":"<span class='searchmatch'>Wikip\u00e9dia</span> may refer to: French <span class='searchmatch'>Wikipedia</span>  Portuguese <span class='searchmatch'>Wikipedia</span>  Hungarian <span class='searchmatch'>Wikipedia</span>  Slovak <span class='searchmatch'>Wikipedia</span> - ",
            "size":464,
            "wordcount":13,
            "timestamp":"2013-08-25T17:14:38Z"
         },
         {
            "ns":0,
            "title":"English Wikipedia",
            "snippet":"The English <span class='searchmatch'>Wikipedia</span> is the English-language  edition of the free online encyclopedia <span class='searchmatch'>Wikipedia</span> .  first edition of <span class='searchmatch'>Wikipedia</span> and remains  <b>...</b> ",
            "size":24753,
            "wordcount":3226,
            "timestamp":"2014-04-16T00:08:42Z"
         },
         {
            "ns":0,
            "title":"Main Page",
            "snippet":"switch: | Monday | Friday From today's featured list ifexist:<span class='searchmatch'>Wikipedia</span>:Today's featured list/ | <span class='searchmatch'>Wikipedia</span>:Today's featured list/ <b>...</b> ",
            "size":6432,
            "wordcount":173,
            "timestamp":"2014-04-13T22:42:14Z"
         },
         {
            "ns":0,
            "title":"Routledge",
            "snippet":"people named Routledge | Routledge (surname)  image. File:Routledge logo. svg | 150px parent Taylor & Francis  | status  | founded 1851 |  <b>...</b> ",
            "size":7549,
            "wordcount":1007,
            "timestamp":"2014-04-08T19:03:39Z"
         },
         {
            "ns":0,
            "title":"Censorship of Wikipedia",
            "snippet":"Censorship of <span class='searchmatch'>Wikipedia</span> has occurred in several countries, including China, France, Iran, Pakistan, Russia, Saudi Arabia, Syria, Thailand,  <b>...</b> ",
            "size":31180,
            "wordcount":4397,
            "timestamp":"2014-03-24T11:04:51Z"
         },
         {
            "ns":0,
            "title":"Wikipedia in culture",
            "snippet":"References to <span class='searchmatch'>Wikipedia</span> in culture have increased as more people learn about and use the online  encyclopedia project.  <span class='searchmatch'>Wikipedia</span>'s  openness <b>...</b> ",
            "size":88661,
            "wordcount":11681,
            "timestamp":"2014-04-19T10:39:15Z"
         },
         {
            "ns":0,
            "title":"Regency",
            "snippet":"Regency (disambiguation)Regency expanded Related. A regency is the period of rule of a regent  or regents. A regent , from the Latin  regens <b>...</b> ",
            "size":1558,
            "wordcount":203,
            "timestamp":"2014-01-03T09:10:26Z"
         },
         {
            "ns":0,
            "title":"Regent",
            "snippet":"date April 2014 A regent, from the Roman regens \"one who reigns\", is the informal or sometimes formal title given to a temporary, acting  <b>...</b> ",
            "size":3053,
            "wordcount":449,
            "timestamp":"2014-04-10T12:31:46Z"
         },
         {
            "ns":0,
            "title":"Peasant",
            "snippet":"File:Prokudin-Gorskii-08. jpg | Young women offer berries to visitors to their izba  home, 1909. Those who had been serfs  among the Russian <b>...</b> ",
            "size":17193,
            "wordcount":2451,
            "timestamp":"2014-04-09T18:30:54Z"
         }
      ],
      "allpages":[
         {
            "pageid":5878274,
            "ns":0,
            "title":"!"
         },
         {
            "pageid":3632887,
            "ns":0,
            "title":"!!"
         },
         {
            "pageid":600744,
            "ns":0,
            "title":"!!!"
         },
         {
            "pageid":34443176,
            "ns":0,
            "title":"!!!Fuck You!!!"
         },
         {
            "pageid":11011780,
            "ns":0,
            "title":"!!!Fuck You!!! And Then Some"
         },
         {
            "pageid":34443184,
            "ns":0,
            "title":"!!!Fuck You!!! and Then Some"
         },
         {
            "pageid":39401265,
            "ns":0,
            "title":"!!! (Chk Chk Chk)"
         },
         {
            "pageid":2556962,
            "ns":0,
            "title":"!!! (album)"
         },
         {
            "pageid":10065458,
            "ns":0,
            "title":"!!! (band)"
         },
         {
            "pageid":16381751,
            "ns":0,
            "title":"!!Destroy-Oh-Boy!!"
         }
      ]
   }
}

那里只有页面的标题,我怎样才能获得链接?谢谢!

1 个答案:

答案 0 :(得分:2)

页面的网址将始终相同,因此您只需将pagetitle附加到基本网址即可。对于英语维基百科:

//en.wikipedia.org/wiki/{PAGETITLE}

如果你没有&#39;知道wiki的url结构(你可能会这么做,因为你只是设法调用API,但无论如何),你可以使用meta指令来获取它:

http://en.wikipedia.org/w/api.php?action=query&meta=siteinfo

返回:

articlepath="/wiki/$1" scriptpath="/w" script="/w/index.php" server="//en.wikipedia.org"