Hi, I also tried to change google search location through http://www.google.co.in/preferences?hl=en#loc , but getting error mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not Found
Here is the code i tried import re import cookielib from mechanize import Browser import mechanize br1= Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br1.set_cookiejar(cj) br1.set_handle_robots(False) br1.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')] P_URL = "http://www.google.co.in/preferences?hl=en#loc" s_page = br1.open(P_URL) loc_form = br1.select_form(name="langform") br1.form['luul'] = u'bangaluru' # <------ New location resp = br1.submit() print "---------resp---------",resp.read() Output ======= $ python a11.py Traceback (most recent call last): File "a11.py", line 94, in ? resp = br1.submit() File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 541, in submit File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 203, in open File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 255, in _mech_open mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not Found =============================================== Date: Wed, 14 Sep 2011 16:31:49 +0530 From: Saju M <sajup...@gmail.com> To: bangpypers@python.org Subject: [BangPypers] Python mechanize Change the Location of Google search Message-ID: <CANR2JHi5=hqvstmrxjhy7gbjqaqluaena9yb4keybmwlk_t...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 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. _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers