Python Google Server

vegetax vegeta.z at gmail.com
Tue Apr 5 11:03:17 EDT 2005


Fuzzyman wrote:


> Add the follwoing two lines to the start of the code :
> 
> import urllib2
> txheaders = { 'User-agent' : 'Mozilla/4.0 (compatible; MSIE 6.0;
> Windows NT 5.1; SV1; .NET CLR 1.1.4322)' }
> 
> Then change the start of the send_head method to this :
> 
>     def send_head(self):
>         """Only GET implemented for this.
>         This sends the response code and MIME headers.
>         Return value is a file object, or None.
>         """
>         print 'Request :', self.path # traceback to sys.stdout
>         url_tuple = urlparse.urlparse(self.path)
>         url = url_tuple[2]
>         domain = url_tuple[1]
>         if domain.find('.google.') != -1:   # bypass the cache for
> google domains
>             req = urllib2.Request(self.path, None, txheaders)
>             return urllib2.urlopen(req)


Doesnt work,the browsers keeps asking me to save the page.

this one works =)

>>  def send_head(self):
    print 'Request :', self.path #| traceback| to| sys.stdout
    url_tuple = urlparse.urlparse(self.path)
    url = url_tuple[2]
    domain = url_tuple[1]
    if domain.find('.google.') != -1: # bypass the cache for google domains
        req = urllib2.Request(self.path, None, txheaders)
        self.send_response(200)
        self.send_header("Content-type", 'text/html')
        self.end_headers()
        return urllib2.urlopen(req)
>>  dotloc = url.rfind('.') + 1






More information about the Python-list mailing list