Python mechanize - two buttons of type 'submit'

前端 未结 4 1577
刺人心
刺人心 2021-02-02 09:42

I have a mechanize script written in python that fills out a web form and is supposed to click on the \'create\' button. But there\'s a problem, the form has two buttons. One fo

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 10:20

    I can talk from experience using HTTP, rather than mechanize, but I think this is probably what you want.

    When there are two submit buttons in a form, a server can determine which one was pressed, because the client should have added an argument for the submit button. So:

    Will take you either the URL:

    blah?button_1=One
    

    or:

    blah?button_2=Two
    

    Depending on which button was pressed.

    If you're programatically determining what arguments are going to be sent, you need to add an argument with the name of the submit button that was pressed, and it's value.

提交回复
热议问题