Searching Wikipedia using API

后端 未结 3 1875
失恋的感觉
失恋的感觉 2020-12-23 12:15

I want to search Wikipedia using the query action. I am using this url:

http://en.wikipedia.org/w/api.php?action=query&format=json&list=search&a

3条回答
  •  太阳男子
    2020-12-23 12:48

    I don't think you can do both in one query.

    1. To get the first result, use the Opensearch API.

    https://en.wikipedia.org/w/api.php?action=opensearch&search=zyz&limit=1&namespace=0&format=jsonfm

    https://en.wikipedia.org/w/api.php
    ?action=opensearch
    &search=zyz          # search query
    &limit=1             # return only the first result
    &namespace=0         # search only articles, ignoring Talk, Mediawiki, etc.
    &format=json         # jsonfm prints the JSON in HTML for debugging.
    

    This will return:

    [
        "Zyz",
        [
            "Zyzomys"
        ],
        [
            ""
        ],
        [
            "https://en.wikipedia.org/wiki/Zyzomys"
        ]
    ]
    

    2. You now have the article name of the first search result. To get the article's first paragram (or description, as you call it), see my answer here: https://stackoverflow.com/a/19781754/908703

提交回复
热议问题