'Using the wikipedia module I can get the url of the first image from a wiki page, but I'm not sure how I would show the image, I'm new to progamming
I'm pretty blind to this kind of stuff as I've only taken 2 semesters of basic python. I am able to get the URL from image fairly easily as you can see in my image() function, I just need a way to show it. It's for a school project so I'm not using python to process data or anything. If I can just print it or show it with pillow that would be ideal. Otherwise I might need to potentially connect this to HTML to use the python as a backend so I can use the <img src=> tag from HTML.
import wikipedia
import urllib.request
from PIL import Image
#restart the program
def restart():
rest = input("Would you like to search something else?(y/n)").lower()
if rest == "y":
start()
else:
end()
#show entire page
def page(search):
print(wikipedia.page(search))
restart()
#summary of page
def summary(search):
sent = input("Short or long summary?").lower()
if sent == "short":
print(wikipedia.summary(search, sentences=1))
if sent == "long":
print(wikipedia.summary(search))
restart()
#show image
def image(search):
url = wikipedia.page(search).images[0]
print("")
def start():
search = input("What would you like to search for?")
print("Other similar items: ")
x = 0
for i in wikipedia.search(search):
x += 1
print(str(x) + ". " + i)
search = input("Which specific item would you like to search for?")
print("What function would you like to use?")
print("1. Pull image")
print("2. Summary")
print("3. Referance")
print("4. Entire wiki page")
function = input("")
if function == "1":
image(search)
if function == "2":
summary(search)
if function == "3":
referance(search)
if function == "4":
page(search)
#main
start()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
