【问题标题】:wikipedia api opensearch not working with. jsonwikipedia api opensearch 无法使用。 json
【发布时间】:2021-01-01 14:15:17
【问题描述】:

我正在使用 wikipedia api 来获取与关键字相关的图像

例如http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&search=mozart&origin=* 正在向我返回数据,我可以从那里提取图像。

将格式更改为jsonhttp://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=mozart&origin=* 我有一个奇怪的结果

[
    "mozart",
    [
        "Mozart",
        "Mozart and scatology",
        "Mozart in the Jungle",
        "Mozart, l'opéra rock",
        "Mozart effect",
        "Mozart family grand tour",
        "Mozart in Italy",
        "Mozart's nationality",
        "Mozart La Para",
        "Mozarteum University Salzburg"
    ],
    [
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
    ],
    [
        "https://en.wikipedia.org/wiki/Mozart",
        "https://en.wikipedia.org/wiki/Mozart_and_scatology",
        "https://en.wikipedia.org/wiki/Mozart_in_the_Jungle",
        "https://en.wikipedia.org/wiki/Mozart,_l%27op%C3%A9ra_rock",
        "https://en.wikipedia.org/wiki/Mozart_effect",
        "https://en.wikipedia.org/wiki/Mozart_family_grand_tour",
        "https://en.wikipedia.org/wiki/Mozart_in_Italy",
        "https://en.wikipedia.org/wiki/Mozart%27s_nationality",
        "https://en.wikipedia.org/wiki/Mozart_La_Para",
        "https://en.wikipedia.org/wiki/Mozarteum_University_Salzburg"
    ]
]

与 xml 格式并不完全相同。

我知道将 xml 转换为 json 并不是很复杂,但我想了解为什么我不能得到正确的输出。

我知道你是否有更好的 api 来获取与关键字相关的图像

【问题讨论】:

    标签: wikipedia-api


    【解决方案1】:

    The documentation 表示“由于性能原因,维基媒体上的 wiki 描述被禁用,因此第二个数组仅包含空字符串。请参阅 T241437。” - 这解释了 json 版本中的空字符串。

    并且“Extension:PageImages 和 $wgPageImagesExpandOpenSearchXml 在 LocalSettings.php 中配置为 true 将允许 XML 格式的每个项目包含带有文章缩略图的标签。” - 这解释了为什么图像以 xml 版本返回。

    您的问题并不完全清楚您在寻找什么,但对于图像,commons api 会更好,例如https://commons.wikimedia.org/wiki/Wolfgang_Amadeus_Mozarthttps://commons.wikimedia.org/wiki/Category:Wolfgang_Amadeus_Mozart 的 API 版本我想那里也有搜索 API。

    【讨论】:

    • 是的。不要使用action=opensearch,除非您正在开发 OpenSearch 客户端(例如 Web 浏览器)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 2014-07-25
    相关资源
    最近更新 更多