I'm new to sockets so i tried to write a code using them in order to retrieve the html code of a page and i got this:
This doesn't work well. I know how to do it using urllib but i wanted to understand sockets. Can anyone help me?Code:import socket mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mySocket.connect(("forum.codecall.net", 80)) mySocket.send("GET / HTTP/1.1\n") mySocket.send("Host: forum.codecall.net\n\n\n") text = mySocket.recv(1024) print text![]()
Code:import socket mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mySocket.connect(("forum.codecall.net", 80)) mySocket.send("GET / HTTP/1.1\n") mySocket.send("Host: forum.codecall.net\n\n") text = '' while 1: data = mySocket.recv(1024) text += data if not data: break mySocket.close() print text
Im new to the whole sockets to, actually i never knew you could obtain html code through sockets on python, but it looks all good.
what for this...Code:while 1: data = mySocket.recv(1024) text += data if not data: break mySocket.close()
Nice =). Thank you very much for your help. I thought the html of the page would all be sent on only one time.
P.S.:I'm sorry for the late answer but i haven't been online in a while.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks