Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: how to retrieve data between <script></script> and save to an array

by curd8341 (Initiate)
on Apr 11, 2012 at 00:47 UTC ( #964432=note: print w/ replies, xml ) Need Help??


in reply to Re^3: how to retrieve data between <script></script> and save to an array
in thread how to retrieve data between <script></script> and save to an array

thanks for the info, Actually I need to add /g besides smi. Here is the script and it works for the string I provided. Here is the code

my @script=(); open FILE, "content" or die "Couldn't open file: $!"; while (<FILE>){ $line .= $_; } close FILE; my $left = quotemeta '<script>'; my $right = quotemeta '</script>'; while( $line =~ /$left(.*?)$right/gsmi ){ push (@script, $1); }

But it will break if $line contains html page with other tags and following <script> contents, for example:

<html> <head> <script language="javascript" src="" id="scptMDtl"></script> <script language="javascript">var onWL=0;var oJS = new Object();</scri +pt> <script language="javascript"> var a_fInDelItms = 0; var a_fPrv = 1; var a_fTxt = 0; </script> </head> <body> <textarea id="txtBdy" class="w100 txtBdy" style="display:none"> This is a test. </textarea> <script language="javascript"> var a_sId = "RgAAAADz6rvTg9+xRIGTnTWlmKbHBwCeJ0LFThYQQaU\/Nvmo +3DG+AAACNa1IAABO5K\/6RD2SRbSFY4IMoQCbAAAAFHnvAAAJ"; var a_sCK = "TuSv+kQ9kkW0hWOCDKEAmwAAABXdNQ=="; </script> </body> </html>

could you please to see how to that by giving this long string, Thanks,


Comment on Re^4: how to retrieve data between <script></script> and save to an array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2013-05-20 07:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (406 votes), past polls