I am trying to submit some data to a form programmatically. I have a small problem when the server "does not like" that I am sending it. Disappointing, there are no error messages or anything that could help diagnose the problem, everything that does it spins me to the same page that I started on when I clicked br.submit() .
When I click the submit button manually in the browser, the summary page shows a little "success!". message. Such a message does not appear when sending through a script. In addition, no changes are actually sent to the server. This is rather strange, and for the first time I came across this behavior.
Delving into Mechanize documents, he suggests that with these strange, hard-to-diagnose problems, it is best to copy the request headers that are actually sent by the browser.
My question is, how can I see request headers when I call br.submit() ?
Code example
location = 'http://ww.mysite.com' br = mechanize.Browser() cj = mechanize.LWPCookieJar() br.set_cookiejar(cj) username = MY_USER_NAME password = MY_PASSWORD br.addheaders.append(('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username, password)))) br.open(location) br.select_form(nr=0) br['text'] = 'MY JUNK TO SUBMIT' #Text field. Can put anything br['DropDown1'] = ['4'] #This is a dropdown of integer values br['DropDown2'] = ['3'] #Also a dropdown of ints br.submit()
How do I know which headers are sent when the form is submitted?
python web-scraping mechanize
Zack Yoshyaro Mar 26 '13 at 22:05 2013-03-26 22:05
source share