34 lines
586 B
Python
34 lines
586 B
Python
import socket
|
|
|
|
|
|
HOST = "vyatsu.ru"
|
|
PORT = 80
|
|
|
|
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
client.connect((HOST, PORT))
|
|
|
|
request = (
|
|
"GET / HTTP/1.1\r\n"
|
|
"Host: vyatsu.ru\r\n"
|
|
"User-Agent: python-socket-lab3\r\n"
|
|
"Accept: text/html\r\n"
|
|
"Connection: close\r\n"
|
|
"\r\n"
|
|
)
|
|
|
|
client.sendall(request.encode("utf-8"))
|
|
|
|
response_parts = []
|
|
while True:
|
|
data = client.recv(4096)
|
|
if not data:
|
|
break
|
|
response_parts.append(data)
|
|
|
|
client.close()
|
|
|
|
response = b"".join(response_parts)
|
|
print(response.decode("utf-8", errors="replace")[:2000])
|
|
|