How to get image URLs in different pages using a single WIKI api call?

拜拜、爱过 提交于 2019-12-04 05:34:02

问题


We can get text extract of different pages in a single wiki api call by using pipe character ( | ).

For eg : http://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=Yahoo|Google&redirects=

By using this api call, we can get datas about Google and Yahoo in text format. Here we get datas of both Google and Yahoo in a single api call.

I want to get image urls of both Google and Yahoo in a single wiki api call. Is there any method to get all image urls of different pages in a single wiki api call?


回答1:


Yes, just switch prop=extracts to prop=images. Works exactly the same way:

http://en.wikipedia.org/w/api.php?action=query&titles=Yahoo|Google&prop=images

The full documentation is here: http://www.mediawiki.org/wiki/API:Properties

To get the url of an image, use prop=imageinfo&iiprop=url for the corresponding file page.

Finally, you can combine it all in one single request, by using the prop=images result as a generator for the prop=imageinfo call:

http://en.wikipedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url&generator=images&titles=Google|Yahoo!



回答2:


There are some warning because you are missing the format=json. So the correct is

https://en.wikipedia.org/w/api.php?action=query&prop=imageinfo&format=json&iiprop=url&generator=images&titles=Google|Yahoo



来源:https://stackoverflow.com/questions/30777792/how-to-get-image-urls-in-different-pages-using-a-single-wiki-api-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!