Searching Wikipedia using the API

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: Get the first lines of a Wikipedia article

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)