用Python mechanize模块填充textarea
是否有一种方法可以使用Python的mechanize模块来填写表单中的文本区域?中有几个在用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
响应
对象中填写文本控件的示例
相关报价:
# 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