May-08-2020, 02:35 AM
I'm making a web scrapping on a website for a private game server using Python. In a part of this website prints the result of the last nation war winner and show 2 messages: "Capella Ganhou!!" and "Procyon Ganhou!!" using the BeautfulSoup library. I made a condition for each event for show the winner nation image into the Label by an url. But for some reason it shows always the last image url and I don't know what is happening. Here is the code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
from tkinter import * import urllib.request from bs4 import BeautifulSoup from IPython.display import Image, display from PIL import Image, ImageTk from io import BytesIO def capella_tg(): resultado_tg = StringVar() try : resultado_tg. set (soup.find_all( "font" )[ 5 ].string) label_resultado_tg = Label(root, textvariable = resultado_tg, font = ( "Consolas" , 25 )).pack() except : return False def procyon_tg(): resultado_tg = StringVar() try : resultado_tg. set (soup.find_all( "font" )[ 4 ].string[ 3 :]) label_resultado_tg = Label(root, textvariable = resultado_tg, font = ( "Consolas" , 25 )).pack() except : return False root = Tk() root.title( "Resultado TG Cabal Ghost" ) soup = BeautifulSoup(page, "html.parser" ) if capella_tg(): with urllib.request.urlopen(url) as u: raw_data = u.read() im = Image. open (BytesIO(raw_data)) image = ImageTk.PhotoImage(im) label = Label(image = image).pack() else : procyon_tg() with urllib.request.urlopen(url) as u: raw_data = u.read() im = Image. open (BytesIO(raw_data)) image = ImageTk.PhotoImage(im) label = Label(image = image).pack() root.mainloop() |