import tkinter as tk import tkinter.scrolledtext as scrolledtext import socket from bs4 import BeautifulSoup class ClientApp: def __init__(self, root): self.root = root root.title("HTTP Client") self.text_area = scrolledtext.ScrolledText(root, width=50, height=20, wrap=tk.WORD) self.text_area.pack(pady=10) # Запускаем бесконечный цикл через 1 секунду после инициализации приложения root.after(1000, self.get_data) def get_data(self): HOST = 'localhost' PORT = 8080 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client: client.connect((HOST, PORT)) client.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') response = client.recv(4096) self.display_table(response.decode('utf-8')) # Повторяем операцию через 1 секунду self.root.after(1000, self.get_data) def display_table(self, response): self.clear_text() # Очищаем текстовое поле перед отображением новых данных soup = BeautifulSoup(response, 'html.parser') table = soup.find('table') if table: rows = table.find_all('tr') for row in rows: cols = row.find_all(['th', 'td']) row_data = [col.get_text() for col in cols] self.text_area.insert(tk.END, '\t'.join(row_data) + '\n') self.text_area.insert(tk.END, '\n') else: self.text_area.insert(tk.END, "No table found in the response.") def clear_text(self): self.text_area.delete('1.0', tk.END) # Удаляем все содержимое текстового поля def main(): root = tk.Tk() app = ClientApp(root) root.mainloop() if __name__ == "__main__": main()