pyhton 模拟浏览器实现

import socket

tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

tcp_socket.connect(("www.lautung.com", 80))

request_line = "GET / HTTP/1.1\r\n"

request_header = "Host:www.lautung.com\r\n"

request_blank = "\r\n"

request_data = request_line + request_header + request_blank

tcp_socket.send(request_data.encode("gbk"))

recv_data = tcp_socket.recv(40960)

recv_text = recv_data.decode()

local_num = recv_text.find("\r\n\r\n")

html_text = recv_text[local_num:]

with open("index.html", "w") as f:
    f.write(html_text)

tcp_socket.close()
上一篇:网络编程之TCP多人聊天


下一篇:python反弹shell