wikipedia api opensearch无法使用.json



我正在使用wikipediaapi获取关键字的相关图像

例如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来获得与关键词相关的图像

文档中说"在Wikimedia上,由于性能原因,Wiki描述被禁用,因此第二个数组只包含空字符串。参见T241437这解释了json版本中的空字符串。

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

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

最新更新