Witam, próbuję napisać aplikację, która wyszukuje dane w internecie. Chciałbym, żeby w między czasie pokazywała progressbar z postępem wyszukiwań. Napisałem taki kod:
import requests
from bs4 import BeautifulSoup
from Service import SQLLiteService as SQL
from GUI import Tools
from tkinter import *
from tkinter import ttk
import time
class OLXService:
def __init__(self, url):
self.Url = url
self.Sql = SQL.DataStorage()
self.Progress = None
self.AllRows = 1100
def init_progress(self):
pw = Tk()
pw.title("Pozyskiwanie danych z serwisu OLX")
pw.resizable(False, False)
Tools.window_size_position(600, 10, pw)
self.Progress = ttk.Progressbar(pw, orient = HORIZONTAL, length = 600, mode = 'indeterminate')
self.Progress.grid(column = 0, row = 0)
time.sleep(2)
def make_step(self):
self.Progress['value'] += 100 / self.AllRows
print(self.Progress['value'])
def get_urls(self):
self.init_progress()
page = requests.get(self.Url)
i = 0
end = False
while end != True:
links = BeautifulSoup(page.content, 'html.parser')
for a in links.find_all('a', href = True, attrs= {'class' : 'marginright5'}):
self.make_step()
self.Sql.exec_query("delete from offerlinks where link = '%s'" % a['href'].split('?')[0])
webpage = None
if 'olx' in a['href'].split('?')[0]:
webpage = 'olx'
else:
webpage = 'otodom'
self.Sql.exec_query("insert into offerlinks (link, webpage) values ('{}', '{}')".format(a['href'].split('?')[0], webpage))
try:
page = requests.get(links.find('a', href = True, attrs= {'data-cy' : 'page-link-next'})['href'])
except:
end = True
def update(self):
return
Niestety progressbar uruchamia się dopiero po tym jak funkcja zakończy swoją pracę :/ Da się jakoś to rozwiązać?