我正在尝试在包含 1 个表单和两个执行不同任务的不同按钮的 PHP/HTML 页面上提交一个 HTML 按钮。我需要提交第二个提交按钮。问题是两个按钮都没有 id 属性,并且仅通过它们的标题标签来区分。我需要通过选择框(我认为这是正确的)选择订单和订单行,然后按表单上的第二个“开始”/提交按钮。例如
<form>
....
<input class="button" type="submit" value="Go">
....
然后再往下我们有...
<select class="sfield" name="last">
<option value="0" selected="">From: First order</option>
<option value="1">From: 19/10/2012 16:22</option>
</select>
<select class="sfield" name="items">
<option value="1" selected="">Include: Orders and items</option>
<option value="0">Include: Order lines only</option>
</select>
<input class="button" type="submit" onclick="this.form.action.value='export'" title="Generate CSV file" value="Go">
我的Python代码片段如下...
br.form['last'] = ['0'] # Select the 'From First Order'
br.form['items'] = ['1'] # Select both Orders and Order Lines
br.submit()
# When I uncomment the line below I can process a CSV file but it just contains Orders only!
# br.open("http://www.mysite.com/admin/ordermanager.php?action=export")
# Read and process CSV file from csv link displayed on repost of submitted form....
# this section below works fine.
for link in br.links(url_regex=r"export",nr=0):
resp = br.follow_link(link)
content = resp.read()
Last_Run_Date = strftime("%Y%m%d%H%M%S", localtime())
with open('c:\python27\%s.csv' % Last_Run_Date, 'w') as fo:
fo.write(content)
似乎没有办法在 br.submit 中指定 title 属性,例如 Mechanize 文档中的 br.submit(title='Generate CSV file') 。我假设 br.submit() 在我想要第二个时选择第一个提交控件?有谁知道解决这个问题的聪明方法?