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

前端 未结 2 1168
礼貌的吻别
礼貌的吻别 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:35

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

    • use list=search as a generator, to get the list of articles
    • use prop=pageimages to get a representative image for each article
    • use prop=extracts to get a description for each article

    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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题