[BangPypers] Python mechanize Change the Location of Google search
Saju M
sajuptpm at gmail.com
Wed Sep 14 13:01:49 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 done following coding.
Issue is, Left side Change Location form of google is javacript
driven, So br.submit() not working .
Have any way to solve this issue ???
import re
from mechanize import Browser
LOGIN_URL = "http://www.google.co.in/search?q=new+york+locksmith&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
br = Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686;
en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9
Firefox/3.0.1')]
s_page = br.open(LOGIN_URL)
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----------", resp.read() #Returning blank
google search page.
More information about the BangPypers
mailing list