Need Help on Script to read a hidden value

naco
naco used Ask the Experts™
on
Hello, i have a program developed in perl but i need a script to make the program find a hidden value in a html text document.
Ex:
<body>
.......
<input type="hidden" value='6291587' name='class_id'>
<input type="hidden" value='4' name='key5'>
<input type="hidden" value='EF3854' name='11'>
</font></form>
</body></html>
it would read the txt with the html source code and show the third line value.. for ex: print EF3854 without the ''.
I have a program that uses the post method, but it needs some keys and values...that value changes all the time so i need it to search it from an .txt(key.txt) file and them send it to the prog so it can do the Post..etc..

the part of the prog is:

var rawfile = key.txt   (THIS WILL BE THE HTML SOURCE TXT FILE)
get url http://www.berny.com/Scripts/ENTERMSG.asp?group=&kkey=&pass_id=213453

var 2wayproc = perl key.pl (THIS WOULD BE THE SCRIPT TO FIND THE HIDDEN VALUE)
   subst KEY6 2wayread
     field pass_id = 213453
     field msg_id = 2666295
     field key5 = 4
     field 11 = $$KEY6$$ (THIS WOULD BE THE KEY I NEED)
     var Referer = http://www.berny.com/Scripts/ENTERMSG.asp?group=&kkey=&pass_id=213453
post url http://www.berny.com/Scripts/ENTERMSG.asp
     print a msg foi impressa


thanks , i really need this help...i tried everything but i could not make it work...it seems to be a simple script to get a value from a txt file...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
hidden values arrive at the script in exactly the same way as <input type="text" ...> values do.  There is no difference that you can detect.  So, whatever method you use for the variables will work.  

Personally I always "roll it myself" so I use soemthing like:
$x=<STDIN>;
@vals=split("&",$x);

but you can use whatever method you like.  Most people seem to like the CGI.pm module.

Author

Commented:
One of the scripts in perl that the prog uses is bellow:
        _______________________________________

# Unbuffer STDOUT
$| = 1;

open FILE,'msgs.txt' || die "Não achei o arquivo com as classes...\n";

@listademsgs = ();

while (<FILE>) {

     if (s/(\/Scripts\/CLASSD.asp\?group=&kkey=&ID=)(\d\d\d\d\d\d\d)/$2/) {
          push (@listademsgs,$2);
     }

}

while (<>) {

     print "$listademsgs[$_]\n";
}
close FILE;

     _________________________________________________
it shows the msgs number(Id)...and prints it to the prog, so it can use it.....
the  MSGS.TXT has the following in it:
part of it is

<B><pre>MSG will be run 12/29/2002</pre>
</pre>
<center><img src="/wsdocs/cyber/PR_BAR.gif" border="0" align="middle"></center>
<a href="/Scripts/CLASSD.asp?group=&kkey=&ID=6352070">  (6352070) </a><br>
<a href="/Scripts/CLASSD.asp?group=&kkey=&ID=6352075"> more classes in about 20 min. (6352075) </a><br>
<center><img src="/wsdocs/cyber/PR_BAR.gif" border="0" align="middle"></center>
<p><font size="2">Record ID=170641
</form></body></html>
</body>
</html>
So you can have an idea of what i need...
I need a script that reads the key.txt that has the
<input type="hidden" value='6291587' name='class_id'>
<input type="hidden" value='4' name='key5'>
<input type="hidden" value='EF3854' name='11'>
</font></form>
</body></html>
and prints out the EF3854 (only without '')....
OBS that value changes all the time...



Commented:
This is the sort of thing you use a tokenizer for.

use HTML::TokeParser;
my $p = HTML::TokeParser->new("key.txt")
  or die "Couldn't parse 'key.txt': $!";

while (my $token = $p->get_tag("input")) {
  if($token->[1]{type} == 'hidden'){
     print $token->[1]{name}.": ";
     print $token->[1]{value}."\n";
  }
}

you might need to grab TokeParser from CPAN, and if you want to know more about how it works, their docs will explain it much better than I can.

In any case, when parsing HTML you always want to use either a tokenizer, or HTML::TreeBuilder if it's more complicated.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial