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

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可以正常工作..

推荐答案

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

1.要获得第一个结果,请使用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.

This will return:

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

2.您现在有了第一个搜索结果的文章名.要获得这篇文章的第一段(或者你所说的描述),请看我的答案:https://stackoverflow.com/a/19781754/908703

Json相关问答推荐

两种情况下过滤的JOLT规范

按照对象键的值对PostgreSQL JSONB对象进行排序'

Jolt将键和值转换为单独的数组集

Golang返回的JSON顶级字段是可变的.如何在 struct 中使用

使用JQ在数组中 Select 第一个具有匹配项的项

PowerShell:使用JSON原生的Short命令处理JSON?

在Databricks中如何将JSON文件作为字典读取

JOLT 转换仅过滤一个字段

try 使用 JQ 转换 JSON 中过于复杂的对象数组

通过 xslt 将内部 json 转换为 xml 时遇到问题

如何将从嵌套 Select 返回的空值转换为空数组?

如何使用 ConfigurationBuilder 解析现有的 json 字符串(不是文件)

如何使用 CORS 实现 JavaScript Google Places API 请求

如何使用 Newtonsoft.Json 反序列化 JSON 数组

将 JSON 数据导入 Google 表格

验证和格式化 JSON 文件

JSON对象中的JavaScript递归搜索

将 Objective-C 对象序列化和反序列化为 JSON

MVC JsonResult camelCase 序列化

如何在 postgresql 9.3 中循环 JSON 数组