image from wikipedia module in python

Solutions on MaxInterview for image from wikipedia module in python by the best coders in the world

showing results for - "image from wikipedia module in python"
Jakob
01 Apr 2019
1import wikipedia
2import requests
3import json
4
5WIKI_REQUEST = 'http://en.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=original&titles='
6
7def get_wiki_image(search_term):
8    try:
9        result = wikipedia.search(search_term, results = 1)
10        wikipedia.set_lang('en')
11        wkpage = wikipedia.WikipediaPage(title = result[0])
12        title = wkpage.title
13        response  = requests.get(WIKI_REQUEST+title)
14        json_data = json.loads(response.text)
15        img_link = list(json_data['query']['pages'].values())[0]['original']['source']
16        return img_link        
17    except:
18        return 0
19
20wiki_image = get_wiki_image('Paris City')
21