Python Mechanize选择一个没有名字的表单 [英] Python Mechanize select a form with no name

查看:297
本文介绍了Python Mechanize选择一个没有名字的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从页面中选择一个表单来进行机械化,但是这个表单在html中没有name属性。我该怎么办?当我尝试使用

  br.select_form(name =)

我得到的错误是没有使用该名称声明表单,并且该函数需要名称输入。只有一种形式的页面,有没有其他的方式可以选择这种形式?

  br.select_form(nr = 0)

选择第一个表单



在Mechanize中 source

  def select_form(self,名称=无,谓词=无,< b> nr =无< / b>):

...
如果提供nr,表格(其中0是
第一个)。


I am attempting to have mechanize select a form from a page, but the form in question has no "name" attribute in the html. What should I do? when I try to use

br.select_form(name = "")

I get errors that no form is declared with that name, and the function requires a name input. There is only one form on the page, is there some other way I can select that form?

解决方案

Try:

br.select_form(nr=0)

to select the first form

In Mechanize source,

def select_form(self, name=None, predicate=None, <b>nr=None</b>):
    """
    ...
    nr, if supplied, is the sequence number of the form (where 0 is the
    first).
    """

这篇关于Python Mechanize选择一个没有名字的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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