S
sajuptpm
Hi,
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
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
========================================= 1
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
========================================= 2
Tried this also, but getting blank google search page.
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-
USfficial&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.
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
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
========================================= 1
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
========================================= 2
Tried this also, but getting blank google search page.
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-
USfficial&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.