How to use HTMLParser silently? 
Author Message
 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="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 )

      end
      def do_input(attrs)
            ah = attrs_to_hash attrs
            if ah['type'] == 'hidden'
                name = ah['name']
                value = ah['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



Mon, 01 Aug 2005 07:40:31 GMT  
 How to use HTMLParser silently?

Quote:

> 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?

use NullFormatter instead of AbstractFormatter.

HTH,




Tue, 02 Aug 2005 11:21:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to use HTMLParser silently? {PlainText email}

2. Difference between HTMLParser and htmllib.HTMLParser

3. puts: program silently blocks

4. tk_getOpen/SaveFile silently fail with odd input

5. changes to shelf items fail silently?

6. Don't silently ignore $env(TCL_LIBRARY)

7. why does popen2 silently ignore IOError?

8. Exiting threads silently

9. application silently dies.

10. htmlPARSER 0.9 beta 1

11. Any Documents on HtmlParser

12. Subclass SGMLParser or HTMLParser?

 

 
Powered by phpBB® Forum Software