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

前端 未结 2 1177
礼貌的吻别
礼貌的吻别 2021-01-31 12:27

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:

  • Title
  • Snippet/Descr
2条回答
  •  春和景丽
    2021-01-31 12:42

    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.

提交回复
热议问题