socket connetion to url with port 80

Fredrik Lundh fredrik at pythonware.com
Tue Apr 4 17:11:58 EDT 2006


"Sakcee" wrote:

> this is really a stupid question,  how can i get page rsponse from a
> site e.g. google.com port 80
> form socket, can i do something
>
> import socket
> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
> s.connect( ( "www.google.com", 80 ) )
> s.send( "Hello" )  # GET??
> response = s.recv(8048)
> print response
>
> can i do soemthign like that , can i send somehting to google and get
> webpage in return, I know that I can use urllib or httplib etc, but can
> i do at socket level?

of course, but it helps if you use the HTTP protocol to talk to
the server:

    http://effbot.org/zone/effnews-1.htm#sending-an-http-request

</F>






More information about the Python-list mailing list