sockets

Allan Zhang allanz at gmail.com
Fri Jan 20 23:15:01 EST 2006


>
>> the following code works perfectly
>>   import socket, sys
>>   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>   s.connect(("www.python.org", 80))
>>   s.send("GET")
here, You need to speak HTTP protocol. I would suggest to change
s.send( "GET / HTTP/1.0\x0d\x0a\x0d\x0a" )


>>   while 1:
>>     buf = s.recv(1000)
>>     if not buf:
>>         break
>>     sys.stdout.write(buf)
>>   s.close()
>>
>>   but the following code does not work
>>
>>     import socket, sys
>>   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>   s.connect(("http://www.google.co.in/search?hl=en&q=india&meta=", 80))
>>   s.send("GET")
It does not work is because you did not speak HTTP

s.connect( ( www.google.co.in, 80) )
s.send( "GET /search?hl=en&q=india&meta= HTTP/1.0\x0d\x0a\x0d\x0a" )



>>   while 1:
>>     buf = s.recv(1000)
>>     if not buf:
>>         break
>>     sys.stdout.write(buf)
>>   s.close()
>>
>> the given url is the google search url for the string india.
>> can u suggest some way to access the google search result page
>> through SOCKETS.
>
>>>> import urllib
>>>> help(urllib)
>
> but this won't help; using scripts to scrape the google search page is
> a violation of their TOS.  for a proper way to do it, see:
>
>    http://www.google.com/apis/
>
> or use yahoo's search service, which is a lot easier to use:
>
>    http://developer.yahoo.net/search/index.html
>    http://developer.yahoo.net/search/web/V1/webSearch.html
>
> </F>
>
>
> 





More information about the Python-list mailing list