1.方式1
import socketclient = socket.socket()# 百度创建连接: 阻塞client.connect(('www.baidu.com',80))# 问百度我要什么?client.sendall(b'GET /s?wd=alex HTTP/1.0\r\nhost:www.baidu.com\r\n\r\n')# 我等着接收百度给我的回复chunk_list = []while True: chunk = client.recv(8096) if not chunk: break chunk_list.append(chunk)body = b''.join(chunk_list)print(body.decode('utf-8'))
2.方式2
import requestsret = requests.get('https://www.baidu.com/s?wd=alex')