From: "Booth, Peter" Date: 2003-02-13T08:40:31+09:00 Subject: How to use HTMLParser silently? This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C2D2F0.189B64BA Content-Type: text/plain 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 (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 ------_=_NextPart_001_01C2D2F0.189B64BA Content-Type: text/html Content-Transfer-Encoding: quoted-printable How to use HTMLParser silently?

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=3D"1.0" = encoding=3D"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 =3D myHttpSession.get(pathQuery)    =

        =         body  =3D page.body

         &n= bsp; 

         &n= bsp;  # use html parser to extract hidden fields

         &n= bsp;  w =3D DumbWriter.new

         &n= bsp;  f =3D = AbstractFormatter.new(w)        =             =             =      

         &n= bsp;  parser =3D PageParser.new(f)

         &n= bsp;  parser.feed(body)

         &n= bsp;  parser.close

         &n= bsp;  hiddenFields =3D parser.hiddenFields

         &n= bsp;  


# = reads the hidden fields in a stream of HTML and exposes them as a = Hash           &n= bsp;           &n= bsp;           &n= bsp;      

class = PageParser < HTMLParser

      attr = :hiddenFields

      def = initialize(f)

         &n= bsp;  super( f )

         &n= bsp;  @hiddenFields=3DHash.new

      end

      def = do_input(attrs)

         &n= bsp;  ah =3D attrs_to_hash attrs

         &n= bsp;  if ah['type'] =3D=3D 'hidden'

         &n= bsp;      name =3D ah['name']

         &n= bsp;      value =3D ah['value']

         &n= bsp;      @hiddenFields[name] =3D = value

         &n= bsp;  end

      end

      def attrs_to_hash( attrs = )

         &n= bsp;  h =3D {}

         &n= bsp;  for a, v in attrs

         &n= bsp;      v =3D = v.split('"')[1]

         &n= bsp;      h[a] =3D v ? v : ''

         &n= bsp;  end

         &n= bsp;  h

      end

end

    

------_=_NextPart_001_01C2D2F0.189B64BA--