0

This is my first time using mechanize and I'm trying to fill out a form with mechanize

Here are my browser options:

br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)


cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)


br.addheaders = 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')]

I fill out the form with valid values and hit br.submit() but it gives me HTTP: Error 500: Internal Server Error. I'm assuming it's detecting that it's a bot or something hitting the submit? But I figured that's what the addheaders was suppose to take care of.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kevin
  • 3,209
  • 9
  • 39
  • 53
  • the part of code that you have works fine. Check that from submitting is actually working on web page or that information that you are filling is correct and doesn't require any additional formatting. Mb you can give a web page on which you are running your script? Also, why you have double 'br.addheaders = br.addheaders =', and spaces between 'en- US'? – 4d4c Mar 14 '13 at 23:20
  • Oops that part was a typo. I'm trying to do this for yahoo signup page (https://edit.yahoo.com/registration?.src=fpctx&.intl=us&.done=http%3A%2F%2Fwww.yahoo.com%2F) so I can get to the Captcha page and analyze the image without manually filling out the registration. I tried to do it on a real browser and it worked so I know the values I'm filling in are working. But when I go to the real yahoo sign up page in a real browser, it gives me this error: Sorry, Unable to process request at this time -- error 999. – Kevin Mar 14 '13 at 23:36
  • Can you show how you submit any of dropdown options (for example gender)? – 4d4c Mar 14 '13 at 23:42
  • br.form['gender'] = ["m"] – Kevin Mar 14 '13 at 23:49

1 Answers1

1

You can use http://grablib.org/docs/, it is much easier and more efficient. Try it. Install on linux:

pip install pycurl lxml

pip install grab

from grab import Grab

g = Grab()
g.go('http://google.com') # go to google.com
g.choose_form(0)  #form number
g.set_input('q', 'test')  # 'q'-input name, 'test' - search query
g.submit()  # send request
print g.xpath_list('//a/text()') # view xpath result link list 

Sorry for my english.

Alexander Zh
  • 111
  • 3