in reply to Parsing Web Page

Smells like a job for HTML::Treebuilder! Which in turn uses HTML::Parser, which in turn uses HTML::Element, which in turn provides you with the ridiculously powerfull look_down method... Assuming $content contains the page you got back;

use HTML::TreeBuilder; my $tree = HTML::TreeBuilder->new; $tree->parse($content); $tree->eof; my @hidden_field_elements = $tree->look_down( _tag => "input", type => "hidden", ); my %hidden_fields = map { $_->attr('name') => $_attr('value') } @hidden_field_elements;

This might work as it is, or it may have some typos in there. You get the <IMG> tag though... Uh... picture.

I must recommend that you not use this method though, because it makes solving this challenge so easy it can only be considered cheating. And you don't wanna be a cheat right?

The man-pages for HTML::Element, ::Parser and ::TreeBuilder are also criminally complete and can easily be used to convince any PHP'r that he's barking up the wrong (pear)tree.

Happy coding!

Replies are listed 'Best First'.
Re: Re: Parsing Web Page
by Gilimanjaro (Hermit) on Jan 20, 2003 at 23:35 UTC
    Would the minus-voters on my response please tell me what is wrong with my post? Okay, it may be a bit jovial, but the solution I offer works, and even after rereading the original problem several times I think this solution fits the proposition 100%... In fact, I used this solution myself for almost exactly the same problem...

    Maybe I upset a few PHP'rs?

      Your post was ok until you mentioned PHP when it become flamebait. No, I'm not PHP fan. No I didn't downvoted you because you actually have good answer. But trolling is inappropriate for perlmonks and many people will downvote you even if you have good answer.

      --
      Ilya Martynov, ilya@iponweb.net
      CTO IPonWEB (UK) Ltd
      Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
      Personal website - http://martynov.org

        Ok... Cool... Point taken... No more flamebait out of my mouth!

        Just to clarify; I used to be a PHP-coder myself until someone showed me the wonderfull world of Perl and more notably CPAN. That's where I long ago found HTML::TreeBuilder amongst many other modules. Which is why the term PHP came to mind...