使用id机械化选择表单 [英] mechanize select form using id

查看:171
本文介绍了使用id机械化选择表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form action =/ monthly-reportsaccept-charset = UTF-8method =postid =sblock> 

这里的表格没有名称。我如何使用 id解析表单

解决方案

这是同样问题的解决方案。 br 是机械化对象:

  formcount = 0 
对于br.forms()中的frm:
if str(frm.attrs [id])==sblock:
break
formcount = formcount + 1
br .select_form(nr = formcount)

我确信上面的循环计数器方法可以做更多pythonic ,但是这应该选择属性为 id =sblock的表单。


I am working on mechanize with python.

<form action="/monthly-reports"  accept-charset="UTF-8" method="post" id="sblock">

The form here does not have a name. How can I parse the form using it's id?

解决方案

I found this as a solution for the same problem. br is the mechanize object:

formcount=0
for frm in br.forms():  
  if str(frm.attrs["id"])=="sblock":
    break
  formcount=formcount+1
br.select_form(nr=formcount)

I'm sure the loop counter method above could be done more pythonic, but this should select the form with attribute id="sblock".

这篇关于使用id机械化选择表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆