Python/Sockets
外观
< Python
Sockets
[编辑]Python可以通过socket通信
连接到服务器
[编辑]import socket, sys
sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
sock.connect ( ( "google.com", 80 ) )#網址包含https或http需先去除,http以80port連接,https以ssl這模組+443port連接
sock.send('GET / HTTP/1.1\r\n')
sock.send('User-agent: Mozilla/5.0 (wikibooks test)\r\n\r\n')
print (sock.recv(4096))