diff --git a/index.html b/index.html deleted file mode 100644 index 652da93..0000000 --- a/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
-Today is a beautiful day!
-Feel free to explore.
-Visit our Page 1.
-
-
-
diff --git a/socket_client.py b/socket_client.py
index f01426b..ffc8eb3 100644
--- a/socket_client.py
+++ b/socket_client.py
@@ -1,14 +1,53 @@
+import tkinter as tk
+import tkinter.scrolledtext as scrolledtext
import socket
+from bs4 import BeautifulSoup
-HOST = 'localhost'
-PORT = 8080
+class ClientApp:
+ def __init__(self, root):
+ self.root = root
+ root.title("HTTP Client")
-def http_client():
- 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(1024)
- print('Response:', response.decode('utf-8'))
+ self.text_area = scrolledtext.ScrolledText(root, width=50, height=20, wrap=tk.WORD)
+ self.text_area.pack(pady=10)
-if __name__ == '__main__':
- http_client()
\ No newline at end of file
+ # Запускаем бесконечный цикл через 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()
diff --git a/socket_server.py b/socket_server.py
index 1ef6cfa..e9c3e7f 100644
--- a/socket_server.py
+++ b/socket_server.py
@@ -2,6 +2,27 @@ import socket
PORT = 8080
HOST = 'localhost'
+TABLES_FILE = 'tables.txt'
+
+def read_text_data(filename):
+ with open(filename, 'r') as file:
+ data = file.read()
+ return data
+
+def generate_html_table(data):
+ lines = data.strip().split('\n')
+ html = "| {header} | " + html += "
|---|
| {item} | " + html += "