Is there a way to fill out textarea that is part of form using mechanize module for Python?
+2
A:
The forms
reference has a couple of examples of filling text controls in response
objects.
A relevant quote:
# 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)
The kind
argument can be used with the form.find_control()
and form.set_value()
methods to locate "text"
controls.
Digging a little into the mechanize _form.py
source, We have an explanation. Mechanize TextControl
covers (among others) the TEXTAREA
form element.
#---------------------------------------------------
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"
gimel
2010-05-21 10:22:02
thanks for giving right direction ...
Asterisk
2010-05-21 10:28:49
+1
A:
You can do something like
import mechanize
br = mechanize.Browser()
br.open("http://pypi.python.org/pypi")
br.select_form("searchform")
br['term'] = "Mechanize"
response = br.submit()
The br['term'] = "Mechanize"
is the relevant line.
And you seriously need to accept some answers on your questions.
Noufal Ibrahim
2010-05-21 10:57:35
It's not that I didn't consider accepting answers, I just didn't know I have to click on CHECKMARK to do that :)
Asterisk
2010-05-21 11:00:11
A:
you can inspect element form first and how many forms in the page can be done with
for form in br.forms():
print form
Gunslinger_
2010-10-03 13:15:26