使用API​​搜索维基百科 [英] Searching Wikipedia using API

查看:126
本文介绍了使用API​​搜索维基百科的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用query操作搜索维基百科.我正在使用以下网址:

I want to search Wikipedia using the query action. I am using this url:

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

那行得通,但我想进入搜索的第一个结果.我该怎么办?

That works but I want to get into the first result of the search. How can I do that?

注意:只有一个结果时,该url才能正常工作. 我只需要标题和简短说明.

Note: That url works fine when there is only one result.. I just need the title and some short description.

推荐答案

我认为您无法在一个查询中同时完成这两项.

I don't think you can do both in one query.

1..要获得第一个结果,请使用 Opensearch API .

1. To get the first result, use the Opensearch API.

https://en.wikipedia.org/w/api.php?action=opensearch&search=zyz&limit=1&namespace=0&format=jsonfm

https://en.wikipedia.org/w/api.php
?action=opensearch
&search=zyz          # search query
&limit=1             # return only the first result
&namespace=0         # search only articles, ignoring Talk, Mediawiki, etc.
&format=json         # jsonfm prints the JSON in HTML for debugging.

这将返回:

[
    "Zyz",
    [
        "Zyzomys"
    ],
    [
        ""
    ],
    [
        "https://en.wikipedia.org/wiki/Zyzomys"
    ]
]

2..您现在拥有第一个搜索结果的文章名称.要获取本文的第一个参数(或描述,如您所称),请在此处查看我的答案: https://stackoverflow.com/a /19781754/908703

2. You now have the article name of the first search result. To get the article's first paragram (or description, as you call it), see my answer here: https://stackoverflow.com/a/19781754/908703

这篇关于使用API​​搜索维基百科的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆