Python机械化-选择一个值并提交不会'不起作用

Python mechanize - selecting a value and submiting doesn't work

本文关键字:提交 不起作用 一个 选择 机械化 Python      更新时间:2024-01-31

HTML代码如下(它是一个字段,旁边有一个按钮,您可以在其中选择值):

<input type="text" name="account_name" class="sqsEnabled" tabindex="0" id="account_name" size="" value="" title='' autocomplete="off">
<input type="hidden" name="account_id" id="account_id" value="">
<button type="button" name="btn_account_name" id="btn_account_name" tabindex="0" title="Select Account" class="button firstChild" value="Select Account"
onclick='open_popup("Accounts", 600, 400,"",true, false,{"call_back_function":"set_return","form_name":"EditView","field_to_name_array":"id":"account_id","name":"account_name"}}, 
"single", true);' >
.....
#the submit button
<input title="Save" accesskey="a" class="button primary" onclick="var _form = document.getElementById('EditView'); _form.action.value='Save'; if(check_form('EditView'))SUGAR.ajaxUI.submitForm(_form);return false;" type="submit" name="button" value="Save" id="SAVE_HEADER">

当我选择值时,HTML会修改前一行,如下所示:

<input type="hidden" name="account_id" id="account_id" value="30a4f430-5b15-8d7f-632a-52723fb0921a">

并且在name="account_name"的输入中有一个字符串值"XXX LTD"

所以我想如果能做到这一点,我会成功提交表格:

    br.select_form(nr=0)
    br.form.set_all_readonly(False)
    form = br.form
    form['account_name'] = "XXX LTD"
    form['account_id'] = "30a4f430-5b15-8d7f-632a-52723fb0921a"
    #other forms ...
    response = br.submit()

Python没有错误,但是表单没有提交。有什么想法吗?提前感谢

问题是您创建了一个dict form但没有使用它,请尝试:

form = br.form
form['account_name'] = "XXX LTD"
form['account_id'] = "30a4f430-5b15-8d7f-632a-52723fb0921a"
br.form = form # <--- here
response = br.submit()

机械化不支持JavaScript。你为什么有这个标签?

您没有选择表单。请使用重新获取您的表单以供选择

br.select_form(nr=0)