Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python mechanize模块填充textarea_Python_Textarea_Mechanize - Fatal编程技术网

用Python mechanize模块填充textarea

用Python mechanize模块填充textarea,python,textarea,mechanize,Python,Textarea,Mechanize,是否有一种方法可以使用Python的mechanize模块来填写表单中的文本区域?中有几个在响应对象中填写文本控件的示例 相关报价: # The kind argument can also take values "multilist", "singlelist", "text", # "clickable" and "file": # find first control that will accept text, and scribble in it form.set_value("r

是否有一种方法可以使用Python的mechanize模块来填写表单中的文本区域?

中有几个在
响应
对象中填写文本控件的示例

相关报价:

# The kind argument can also take values "multilist", "singlelist", "text",
# "clickable" and "file":
#  find first control that will accept text, and scribble in it
form.set_value("rhubarb rhubarb", kind="text", nr=0)
kind
参数可与
窗体一起使用。find_control()
窗体。set_value()
方法可定位
“text”
控件

深入研究一下,我们有一个解释。机械化
TextControl
覆盖
TEXTAREA
表单元素

#---------------------------------------------------
class TextControl(ScalarControl):
    """Textual input control.

    Covers:

    INPUT/TEXT
    INPUT/PASSWORD
    INPUT/HIDDEN
    TEXTAREA

    """
    def __init__(self, type, name, attrs, index=None):
        ScalarControl.__init__(self, type, name, attrs, index)
        if self.type == "hidden": self.readonly = True
        if self._value is None:
            self._value = ""

    def is_of_kind(self, kind): return kind == "text"

你可以这样做

import mechanize

br = mechanize.Browser()
br.open("http://pypi.python.org/pypi")
br.select_form("searchform")
br['term'] = "Mechanize"
response = br.submit()
br['term']=“Mechanize”
是相关行


您需要认真地接受一些关于您的问题的答案。

您可以首先检查元素表单以及页面中可以使用多少表单

for form in br.forms():
    print form