mercredi 19 mai 2021

displaying data from web scraping into gui

whenever I try it, the GUI doesn't show up the output shows on the pyhton console instead of as a label on the root window please i need help also any other correction on my sample code

from tkinter import *
from urllib.request import *

from bs4 import BeautifulSoup


def scrape():
    page = urlopen("https://www.oreilly.com/library/view/web-scraping-with/9781491985564/ch01.html")
    webobj = BeautifulSoup(page, "html.parser")
    datas = webobj.find_all(["p"])
    for data in datas:
        return str(data)


def getout():
    import sys
    sys.exit()


datam = scrape()

# the program starts here
root = Tk()
lab = Label(root, text=datam)
lab.pack()
but = Button(root, text="Exit", command=getout())
but.pack()
root.title("My tkinter program")

# this loops the program until cancel button is pressed
root.mainloop()



Aucun commentaire:

Enregistrer un commentaire