Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Get specific values from look_down method of HTML::TreeBuilder

by kalyanrajsista (Scribe)
on Jan 07, 2010 at 07:47 UTC ( #816039=perlquestion: print w/ replies, xml ) Need Help??
kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the following code to extract the hidden values from an HTML page. Is there any way that I can extract only specific hidden values or any other values matching the criteria defined in look_down method. In this case I want only recid1,country values

I tried passing array reference to name, but it isn't working for me...any Ideas please

use strict; use warnings; use HTML::TreeBuilder; my $t = HTML::TreeBuilder->new_from_file(*DATA); my @hidden_inputs = $t->look_down( _tag => q{input}, type => q{hidden}, name => q{recid1}, ); for my $hidden_input (@hidden_inputs){ printf qq{*%s*\n}, $hidden_input->attr(q{value}); } __DATA__ <html><head> <title>Data</title> </head> <form name="action"> <table cellspacing="1" cellpadding="1"> <tr> <td>File name</td> <td>From To</td> <td>Svc</td> <td>Period</td> <td>Seq#</td> <td>Reason for Rejection</td> <td>Next Action</td> <td>Country</td> </tr> <tr> <td>Sample.XML</td> <td><a href='dch_redirect?refer=10293377&ref=10293377'>USA-IND</a></ +td> <td>Voice</td> <td><input type="hidden" name="recid1" value="10293377">2009/08</td> <td>03386</td> <td>data already exists</td> <td><input type="checkbox" name="c_1"></td> <td><input type="hidden" name="country" value="America">USA</td> </tr> </body></html>

Comment on Get specific values from look_down method of HTML::TreeBuilder
Download Code
Re: Get specific values from look_down method of HTML::TreeBuilder
by Anonymous Monk on Jan 07, 2010 at 07:58 UTC
    Is there any way that I can extract only specific hidden values

    I don't understand, your code does exactly that, what is your question?

      Sorry for putting in confusion. Below code extracts all the hidden values from HTML

      my @hidden_inputs = $t->look_down( _tag => q{input}, type => q{hidden}, );

      I want specific hidden values like recid1 and country with the below code, but isn't working

      my @hidden_inputs = $t->look_down( _tag => q{input}, type => q{hidden}, name => ['recid1', 'country'] );
        I see. look_down supports strings and regex only, so you can use
        name => qr'recid1|country',

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://816039]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-12-27 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls