Chris Lowth <> wrote in
news:LNZze.26101$:
> wrote:
....
>> <form name="ecomm_frm" method="post"
>> action="process.aspx?c=us&l=en&" id="ecomm_frm">
>> <input type="hidden" name="TARGET" value="Button" />
>> <input type="hidden" name="ARGUMENT" value="" />
>> <input type="hidden" name="STATE"
>> value="wxMDcyMzEwNzIyO3Q8O2w8aTwwPjs" />
>>
>>
>> How can I extract the value ("wxMDcyMzEwNzIyO3Q8O2w8aTwwPjs") for
>> STATE from this text ? The length of string for "value" is not a
>> constant. can you guys help me to figure this out? Thanks
....
> If all your text is in $text, then this should do it..
>
> if ( $text =~ m!<input type="hidden" name="STATE" value="(.*?)"/>!s )
> {
> print "$1\n";
> }
You should use an HTML parser to parse HTML:
#!/usr/bin/perl
use strict;
use warnings;
my $form = do { local $/; <DATA> };
if ( $form =~ m!<input type="hidden" name="STATE" value="(.*?)"/>!s ) {
print "$1\n";
}
__END__
<form name="ecomm_frm" method="post"
action="process.aspx?c=us&l=en&" id="ecomm_frm">
<input type="hidden" name="TARGET" value="Button" />
<input type="hidden" name="ARGUMENT" value="" />
<input type="hidden" name="STATE" value="wxMDcyMzEwNzIyO3Q8O2w8aTwwPjs"
/>
D:\Home> ttt
D:\Home>
One can, instead, use a proper HTML to parse HTML:
#!/usr/bin/perl
use strict;
use warnings;
use HTML::TokeParser::Simple;
my $form = do { local $/; <DATA> };
my $p = HTML::TokeParser::Simple->new(\$form);
while(my $t = $p->get_token) {
if( $t->is_start_tag('input')
and 'STATE' eq $t->get_attr('name') ) {
print $t->get_attr('value')."\n";
}
}
__END__
<form name="ecomm_frm" method="post"
action="process.aspx?c=us&l=en&" id="ecomm_frm">
<input type="hidden" name="TARGET" value="Button" />
<input type="hidden" name="ARGUMENT" value="" />
<input type="hidden" name="STATE" value="wxMDcyMzEwNzIyO3Q8O2w8aTwwPjs"
/>
D:\Home> ttt
wxMDcyMzEwNzIyO3Q8O2w8aTwwPjs
> --
> http://www.lowth.com/rope - Scriptable IP packet match logic for
> linux/iptables.
Incidentally, your signature delimiter is incorrect. It should be two
dashes followed a space on a line by itself.
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html