Change Location in the google search page

sajuptpm sajuptpm at
Thu Sep 15 09:44:55 CEST 2011


I want to open Google search page and Change the Location link in the
left hand nav of Google) from the users current location to a
different location, then return the results of the updated search.

I tried to change google search location through , but getting error
mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not

Here is the code i tried

========================================= 1

import re
import cookielib
from mechanize import Browser
import mechanize

br1= Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()

br1.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv: Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

P_URL = ""
s_page =
loc_form = br1.select_form(name="langform")
br1.form['luul'] = u'bangaluru' # <------ New location
resp = br1.submit()
print "---------resp---------",


$ python
Traceback (most recent call last):
  File "", line 94, in ?
    resp = br1.submit()
  File "build/bdist.linux-i686/egg/mechanize/", line 541,
in submit
  File "build/bdist.linux-i686/egg/mechanize/", line 203,
in open
  File "build/bdist.linux-i686/egg/mechanize/", line 255,
in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not Found

========================================= 2

Tried this also, but getting blank google search page.

import re
from mechanize import Browser


br = Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686;
en-US; rv: Gecko/2008071615 Fedora/3.0.1-1.fc9

s_page =
loc_form = br.select_form(nr=1)
loc_text_fld = br.form.find_control(id='lc-input')
loc_text_fld.__dict__['_value'] = 'kerala' #Change the Location
resp = br.submit()

print "\n\n----------resp----------", #Returning blank
google search page.

More information about the Python-list mailing list