1

这是 HTML:

<form method="post" action="./xxxxx" name="form1">
    <input type="hidden" name="requestKey" value="52032a76cf53340b07052fd143feddc4a9d8f18130c80ec86003ab56e0d91b36"/>
    <input type="hidden" name="option" value="txnlist">
    <input type="hidden" name="account" value='1336169999'>
    <input type="hidden" name="app" value="D">
    <input type="hidden" name="lockType" value="">

    <p><span class="header2">&nbsp;Statement options </span>
        <table summary="" width="100%" border="0" cellpadding="1" cellspacing="1">
            <tr>
                <td width="20"></td>
                <td width="20"><input type="radio"  name="optDateFilter" value="1"></td>
                <td>Transactions for the last 30 days</td>
                <td></td>
            </tr>
            <tr>
                <td width="20"></td>
                <td width="20"><input type="radio" name="optDateFilter"  value="2"></td>
                <td>Transactions for the last 90 days</td>
                <td></td>
            </tr>
            <tr>
                <td width="20">&nbsp;</td>
                <td width="20"><input type="radio" name="optDateFilter" checked='checked' value="3" style="vertical-align: middle"></td>
                <td>
                    <div>
                        <font style="vertical-align: middle;">Transactions from&nbsp;</font>
                        <script src='jquery/js/ui/min/jquery.ui.datepicker.min-1.8.10.js'></script>
                        <script type='text/javascript'>$(function() {$('#datepicker1').datepicker( { changeMonth : true, changeYear : true, dateFormat : 'dd/mm/yy', showOn: 'both', buttonImage: 'images/calendar.png', buttonImageOnly: true }); }); </script>
                        <input type='text' id='datepicker1' name='txtFromDate' size='11' maxlength='10' value='14/12/2012' onchange="checkFromDate(document.form1.txtFromDate.value);document.form1.optDateFilter[2].checked = true;">
                        <font style="vertical-align: middle;">to</font>
                        <script type='text/javascript'>$(function() {$('#datepicker2').datepicker( { changeMonth : true, changeYear : true, dateFormat : 'dd/mm/yy', showOn: 'both', buttonImage: 'images/calendar.png', buttonImageOnly: true }); }); </script>
                        <input type='text' id='datepicker2' name='txtToDate' size='11' maxlength='10' value='01/01/2013' onchange="checkToDate(document.form1.txtFromDate.value,document.form1.txtToDate.value);document.form1.optDateFilter[2].checked = true;">
                    </div>
                </td>
                <td><font style="font-size: 8pt; vertical-align: middle;"><i>(maximum date range 3 months)</i></font></td>
            </tr>
        </table>
        <table summary="" cellpadding="1" cellspacing="1" border="0">
            <tr>
                <td width="20">&nbsp;</td>
                <td width="20">
                    <a  href="javascript:if(document.form1.optDateFilter[2].checked==true){CheckAndSubmit(document.form1.txtFromDate.value,document.form1.txtToDate.value);}else{showOverlay();document.form1.submit();};">
                         <img src="images/proceed.gif" alt="Show the selected range of transactions" border="0" width="22" height="22" />
                    </a>
                </td>
                <td>
                    <a  href="javascript:if(document.form1.optDateFilter[2].checked==true){CheckAndSubmit(document.form1.txtFromDate.value,document.form1.txtToDate.value);}else{showOverlay();document.form1.submit();};" title="Show the selected range of transactions">Show the selected range of transactions</a>
                </td>
            </tr>
    </table>
</form>

这是我拥有的代码,但它不起作用:

self.browser.select_form('form1')
self.browser.form.set_all_readonly(False)
self.browser['txtFromDate'] = '28/12/12'
self.browser['txtToDate'] = '01/01/13'
resp = self.browser.submit()
html = resp.read()
4

2 回答 2

1

我想我必须这样做

    self.browser.select_form('form1')
    self.browser['optDateFilter'] = ['2'] 
    self.browser.form.find_control(name="txtFromDate", id="datepicker1").value = "13/10/12"
    self.browser.form.find_control(name="txtToDate", id="datepicker2").value = "01/01/13"
    resp = self.browser.submit()
于 2013-01-11T07:41:09.000 回答
1

mechanize 有一个奇怪的怪癖:由于 HTML 文档中可以有多个同名的单选按钮元素,因此它坚持使用列表作为值,即使任何时候都只能选择一个单选按钮。这意味着你需要使用这个:

  self.browser.form.find_control(name='optDateFilter').value = ['2']

这同样适用于更有意义的复选框,因为允许用户选择多个值。

于 2013-01-11T09:03:51.760 回答