Wikipedia API全文搜索可返回带有标题,代码段和图像的文章 [英] Wikipedia api fulltext search to return articles with title, snippet and image
问题描述
我一直在寻找一种基于搜索字符串来查询具有以下属性的文章列表的Wikipedia api的方法:
I've been looking for a way to query the wikipedia api based on a search string for a list of articles with the following properties:
- 标题
- 摘要/说明
- 与该文章相关的一个或多个图像.
我还必须使用jsonp进行查询.
I also have to make the query using jsonp.
我尝试使用list = search参数
I've tried using the list=search parameter
但是似乎忽略了prop = images,我也尝试使用prop = imageinfo和prop = pageimages进行变体.但是它们都给我与使用list = search相同的结果.
But it seems to ignore the prop=images, I've also tried variations using the prop=imageinfo and prop=pageimages. But they all give me the same result as just using the list=search.
我也尝试过action = opensearch
I've also tried action=opensearch
http://en.wikipedia.org /w/api.php?action=opensearch&search=test&limit=10&format=xml
当我设置format = xml时,这正是我想要的,但是当使用format = json时返回一个简单的页面标题数组,因此由于jsonp的要求而失败.
Which gives me exactly what I want when i set format=xml, but returns a simple array of page titles when using format=json and therefore fails because of the jsonp requirement.
还有另一种方法可以做到这一点吗?我真的很想在一个请求中解决此问题,而不是先使用title = x | y | z
Is there another approach to doing this? I'd really like to solve this in a single request rather than make the first search request and then a second request for the images using titles=x|y|z
推荐答案
正如Bergi所建议的,使用生成器是解决问题的方法.具体我该怎么做:
As Bergi suggested, using generators is the way to go here. Specifically what I would do:
- 使用
list=search
作为生成器,以获取文章列表 - 使用
prop=pageimages
获取每篇文章的代表性图像 - 使用
prop=extracts
获取每篇文章的说明
整个查询看起来像这样:
The whole query could look like this: