Horje
image from wikipedia module in python Code Example
image from wikipedia module in python
import wikipedia
import requests
import json

WIKI_REQUEST = 'http://en.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=original&titles='

def get_wiki_image(search_term):
    try:
        result = wikipedia.search(search_term, results = 1)
        wikipedia.set_lang('en')
        wkpage = wikipedia.WikipediaPage(title = result[0])
        title = wkpage.title
        response  = requests.get(WIKI_REQUEST+title)
        json_data = json.loads(response.text)
        img_link = list(json_data['query']['pages'].values())[0]['original']['source']
        return img_link        
    except:
        return 0

wiki_image = get_wiki_image('Paris City')




Python

Related
python append list Code Example python append list Code Example
how append a directory based on current directory python Code Example how append a directory based on current directory python Code Example
how to split string with comma in python Code Example how to split string with comma in python Code Example
increase pie chart size python Code Example increase pie chart size python Code Example
multirow np.rand.randint Code Example multirow np.rand.randint Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7