Apologies for first sending this as HTML
Can anyone help with the following? I am using HTMLParser to extract hidden
fields from a form using the following code. It does what I want, but it
also writes out tokens from the parsing to standard out. Is there anyway to
do this silently?
Peter Booth
<?xml version="1.0" encoding="UTF-8" ?> (image) (image) (image)
(image)
(image) (image) (image) (image) (image) (image) (image) Please Log In
(image) (image) (image) (image) (image) (image) (image) (image)
(image)
(image) (image) (image) (image) (image) User Name: (image) (image)
Password: (image) (image) (image) (image) Remember my User Name
(image)
(image) (image) (image) (image) (image) (image) (image) (image)
(image)
(image) (image)(image) (image) (image) (image) (image) (image) If you
have a SecurID card, please enter your SecurID password/PIN followed
by
page = myHttpSession.get(pathQuery)
body = page.body
# use html parser to extract hidden fields
w = DumbWriter.new
f = AbstractFormatter.new(w)
parser = PageParser.new(f)
parser.feed(body)
parser.close
hiddenFields = parser.hiddenFields
# reads the hidden fields in a stream of HTML and exposes them as a Hash
class PageParser < HTMLParser
attr :hiddenFields
def initialize(f)
super( f )
@hiddenFields=Hash.new
end
def do_input(attrs)
ah = attrs_to_hash attrs
if ah['type'] == 'hidden'
name = ah['name']
value = ah['value']
@hiddenFields[name] = value
end
end
def attrs_to_hash( attrs )
h = {}
for a, v in attrs
v = v.split('"')[1]
h[a] = v ? v : ''
end
h
end
end