import requests


def get_word_count(title, base_url="https://klexikon.zum.de/api.php") -> int:
    """
    Return the word count of an Klexikon article.
    :param title:
    :param base_url
    :return:
    """
    params = {
        "action": "query",
        "format": "json",
        "list": "search",
        "srlimit": 5,
        "srsearch": title
    }
    try:
        res = requests.get(url=base_url, params=params)
        # print(len(res.json()['query']['search']))
        article = res.json()['query']['search'][0]
        return article['wordcount']
    except IndexError:  # Likely due to incorrect search results.
        return 0