When I run the following code
import socket
import urlparse
import re
import os
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect(("www.google.co.in", 80))
s.send("GET /?gfe_rd=cr&gws_rd=cr HTTP/1.0\r\n\r\n")
data = s.recv(100000)
print data
s.close()
The response I get from google is always the following
HTTP/1.0 302 Found
Location: http://www.google.co.in/?gfe_rd=cr&gws_rd=cr
Cache-Control: private
Content-Type: text/html; charset=UTF-8
P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
Date: Mon, 04 Jan 2016 04:30:53 GMT
Server: gws
Content-Length: 245
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=75=chG9KySsUncl-1elqXhs56m7cNHxFvFwNR5pZoavIwRJ2PpoGlm5RbShdsiF7udrTgwZgG-eRo4oQqA0RhbfwtExcxUGk88F_R2TNV9vi4XKhWSB9ihhcqulYTtg9xGkagSDPdFfmw; expires=Tue, 05-Jul-2016 04:30:53 GMT; path=/; domain=.google.com; HttpOnly
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.in/?gfe_rd=cr&gws_rd=cr">here</A>.
</BODY></HTML>
I understand this is because I did not follow the redirects. Could someone explain which url I should connect to so that I do not get this error, or how can I fix this problem?