views:

78

answers:

2

I am creating a script using Python Mechanize that can login to a website and submit a form. However, this form has 3 submit buttons (Preview, Post, and Cancel). I'm used to only one button...

This is the form:

<TextControl(subject=Is this good for the holidays? Anyone know about the new tech?)>
  <IgnoreControl(threads=<None>)>
  <TextareaControl(message=Im new to technology stocks.)>
  <SelectControl(identity=[*annamae41g])>
  <RadioControl(E=[5, 4, *3, 2, 1, 0])>
  <SubmitControl(SubmitPreview=Preview Message) (readonly)>
  <SubmitControl(SubmitPost=Post Message) (readonly)>
  <SubmitControl(SubmitCancel=Cancel) (readonly)>
  <HiddenControl(action_btn=) (readonly)>
  <HiddenControl(_charset_=) (readonly)>
  <HiddenControl(.crumb=4DxnFEwMIGG) (readonly)>
  <HiddenControl(r=/Stocks_(A_to_Z)/Stocks_G) (readonly)>
  <HiddenControl(bn=25263) (readonly)>
  <HiddenControl(<None>=annamae41g) (readonly)>>

And this is my code:

br.open(newtopic_url)
br.select_form(name="postmsg")
br.form['subject'] = "Is this good for the holidays? Anyone know about the new tech?"
br.form['message'] = "Im new to technology stocks."
br.form['E'] = ['3']
br.form['identity'] = ['annamae41g']
print br.form
br.submit()

If I run this script...it won't work. Nothing happens. I am assuming since it has 3 submit buttons in the form? Or is it another issue?

A: 

problem solved.

Do not use python mechanize. It won't let you send other post data.

For some reason, the post data currently in the question is NOT sufficient. There are other stuff that needs to be sent to the server.

Therefore, you must use the regular opener/cookiejar method to send all the data through. I got the additional data (besides subject, message, E, identity) from Firebug (looking at the NET)

TIMEX
A: 

I had the same problem as you.

A form with two submit buttons, first was preview, second was submit.

At first, mechanize was using only the first button, I could see the server answer using

response = browser.submit()
print response.read()

I put the submit button name as a parameter to the mechanize submit function, and it worked!

response = browser.submit("submit")

Test it, it should work for you too!

Dasanjos