本帖最后由 xiaosi4081 于 2020-6-6 15:29 编辑
错误:User_Agent
正确:User-Agentimport ssl
import socket
host = "www.douban.com"
port = 443
User-Agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
client_sk = ssl.wrap_socket(socket.socket())
client_sk.connect((host,port))
request = 'GET HTTP/1.1\r\nhsot:{} User-Agent:{}\r\n\r\n'.format(host,User-Agent).encode('utf8')
client_sk.send(request)
response = client_sk.recv(1024).decode('utf8')
print(response)
|