import mechanize
mech = mechanize.Browser()
try:
    mech.open('http://www.google.com/')
except HTTPError as e:
    sys.exit('%d: %s' % (e.code, e.msg))
mech.select_form(nr=0)
mech['query'] = 'Lester'
try:
    mech.submit()
except HTTPError as e:
    sys.exit('post failed: %d: %s' % (e.code, e.msg))
how to make python 3.x enter text into a web browser