Wikipedia api fulltext search to return articles with title, snippet and image

只愿长相守 提交于 2019-12-02 17:44:22

As Bergi suggested, using generators is the way to go here. Specifically what I would do:

The whole query could look like this:

http://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrsearch=test&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max

I've tried using the list=search parameter, but it seems to ignore the prop=images

If you want to retrieve any properties, you need to specify a list of pages for which you want to get these; e.g. by using the titles=, pageids=, or revids= parameters. You didn't send any, so you did not get a result for the prop=images.

If you did use api.php?action=query&list=search&srsearch=test&prop=images&titles=test you would have gotten the search results for test and the images of the Test page.

You can however also use the collection that the list query generates for your property query, using the list module as a generator. The query would look like api.php?action=query&generator=search&gsrsearch=test&gsrnamespace=0&gsrprop=snippet&prop=images. Unfortunately, it does not yield the attributes that the list contained, but only used the pageids for a basic property query.

Using two queries is probably the way to go. Btw, I'd recommend to use the pageimages property, it will likely give you the best results.

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