Как добавить к лейблам время взятое с сайта (Ссылка в коде)
# Ссылка = https://www.vremyanamaza.ru/%D0%94%D0%B5%D1%80%D0%B1%D0%B5%D0%BD%D1%82/%D0%B2%D1%80%D0%B5%D0%BC%D1%8F-%D0%BD%D0%B0%D0%BC%D0%B0%D0%B7%D0%B0-%D0%94%D0%B5%D1%80%D0%B1%D0%B5%D0%BD%D1%82/9851-mwl07
from tkinter import *
import requests
from bs4 import BeautifulSoup as BS
#WEB
r = requests.get("https://www.vremyanamaza.ru/%D0%94%D0%B5%D1%80%D0%B1%D0%B5%D0%BD%D1%82/%D0%B2%D1%80%D0%B5%D0%BC%D1%8F-%D0%BD%D0%B0%D0%BC%D0%B0%D0%B7%D0%B0-%D0%94%D0%B5%D1%80%D0%B1%D0%B5%D0%BD%D1%82/9851-mwl07")
html = BS(r.content,"html.parser")
#FUNCTIONS
def foo(event):
for el in html.select('.item'):
time = el.select_one(".prayerTime > span")
if not time:
continue
# label_3['text'] = 'Твой BMI {0}'.format(result)
items = []
items.append(str(time))
one["text"] += items[0]
two["text"] += items[1]
three["text"] += items[2]
four["text"] += items[3]
five["text"] += items[4]
#WINDOW
win = Tk()
#WINDOW CONFIG
win.title("Prayer Time")
win.geometry("300x250")
# win.resizable(height=False,width=False)
win.configure(bg="#008A59")
#WINDOW ITEMS
label = Label(win,text="Время намаза",fg="#fff",bg="#008A59",font=("Roboto Mono",15,"bold"))
btn = Button(win,text="Узнать время",fg="#fff",bg="#005F59",font=("Roboto Mono",12,"bold"))
one = Label(win,text="Фаджр -",fg="#fff",bg="#008A59",font=("Roboto Mono",13,"bold"))
two = Label(win,text="Зухр -",fg="#fff",bg="#008A59",font=("Roboto Mono",13,"bold"))
three = Label(win,text="Аср -",fg="#fff",bg="#008A59",font=("Roboto Mono",13,"bold"))
four = Label(win,text="Магриб -",fg="#fff",bg="#008A59",font=("Roboto Mono",13,"bold"))
five = Label(win,text="Иша -",fg="#fff",bg="#008A59",font=("Roboto Mono",13,"bold"))
label.place(x=70,y=10)
btn.place(x=70,y=210,width=160)
one.place(x=70,y= 50)
two.place(x=70,y= 80)
three.place(x=70,y= 110)
four.place(x=70,y= 140)
five.place(x=70,y= 170)
btn.bind("<Button-1>",foo)
win.mainloop()
Ответы (1 шт):
Автор решения: Wairua
→ Ссылка
Добавьте в import
import re
И замените функцию foo на :
def foo(event):
items = [re.search(r'(\d{2}:\d{2})', el.text).group(0)
for el in html.find_all('div', {'class': 'prayerTime'})]
one["text"] += ' ' + items[0]
two["text"] += ' ' + items[1]
three["text"] += ' ' + items[2]
four["text"] += ' ' + items[3]
five["text"] += ' ' + items[4]