[BangPypers] RE : Python mechanize Change the Location of Google search

2011-09-15 Thread Saju M
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+locksmithie=utf-8oe=utf-8aq=trls=org.mozilla:en-US:officialclient=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


Re: [BangPypers] RE : Python mechanize Change the Location of Google search

2011-09-15 Thread Senthil Kumaran
On Thu, Sep 15, 2011 at 3:31 PM, Saju M sajup...@gmail.com wrote:
 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

Mechanize does not support any action done via Javascript and there
seems a javascript call involved in setting the location there.
Turn Javascript off in your browser and try to change the location.
You will notice that it throws errors.

Perhaps it is the same which is happening when accessed via mechanize.

BTW, do you really need mechanize for the task that you are trying to do?

Would not their AJAX API
(http://code.google.com/apis/websearch/docs/#fonje_snippets ) help you
to accomplish the same with lesser hassle ? (at least until they
retire it :))

---
Senthil
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] (no subject)

2011-09-15 Thread Nikunj Badjatya
+1

:)




On Mon, Sep 12, 2011 at 7:34 PM, AKARSH SANGHI akarsh.san...@gmail.comwrote:

 Hey, here's a great video with Python in it.

 http://youtu.be/1lBeungEnx4

 Although it's also about matlab.

 --

 Akarsh Sanghi
 Jaypee Institute of Information Technology University
 Undergraduate Student Class of 2013
 Mob: (+91)-9818489945
 Email: akarsh.san...@gmail.com
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers