in reply to Re^4: Email - jquery
in thread Email - jquery
At the risk of upsetting the keepers of the "Thou shalt not parse web pages with regular expressions" commandment (who are almost always correct), here is a fragile solution that works, for the sample input you provided and for the web page complete:
use strict; use warnings; use utf8; use feature qw/unicode_strings say/; my $doc = do{ local $/ = undef; <DATA>; }; say GetEmailLink($doc) // 'Unable to parse document.'; sub GetEmailLink { my $document = shift; my %component = fetch_obscured_email($document); return unless keys %component; # Detect and pass along failure to pa +rse. my $link = q(); for( my $i = 0; $i != @{$component{cypher}}; ++$i ) { my $linkChar = $component{cypher}[$i] - $component{key}[$i % @{$co +mponent{key}}]; $link .= chr($linkChar); } return $link; }; sub fetch_obscured_email { my $data = shift; $data =~ m/ SetEmailLink\s*\(\s* # Function name and opening paren +(anchor). [^,]*, # Unwanted first parameter. \s* \[ \s* ( [^]]+ ) \s* \] \s*, # Wanted second parameter. [^,]*, # Unwanted third parameter. \s* \[ \s* ( [^]]+ ) \s* \] \s* # Wanted fourth parameter. \s*\) # Closing paren. /x or return; # Condition: Failure to parse. my( $text_param, $key_param ) = ( $1, $2 ); tr/0-9,//dc for $text_param, $key_param; # Keep only what we need +. return( cypher => [ split /,/, $text_param ], key => [ split /,/, $key_param ] ); } __DATA__ <script type="text/javascript"> //<![CDATA[ jQuery(function () { SetEmailLink('phmain_1_phrightcontent_0_lnkEmail', [113,104,125,164,11 +8,187,87,149,128,146,184,114,53,138,161,112,176,146,143,76,160,188,11 +2,114,121,154,113,190,132,80,112,152], [], [4,7,20,56,2,76,29,34,12,4 +5,83]); });//]]> </script>
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Email - jquery
by bib (Initiate) on Feb 09, 2014 at 21:43 UTC |