I'm trying to get the visible content from here using socket
but unfortunately I'm getting an error when I execute my script. As I'm very new to code using socket
, I can't understand as to where I'm going wrong.
My code:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_ip = socket.gethostbyname('data.pr4e.org')
s.connect((host_ip,80))
cmd = "GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n".encode()
s.send(cmd)
while True:
data = s.recv(1024)
if (len(data) <1 ):
break
print(data.decode())
s.close()
Error I'm getting:
400 Bad Request
Your browser sent a request that this server could not understand.