Re: Parsing javascript with html::tokeparser
- From: "Bart Van der Donck" <bart@xxxxxxxxxx>
- Date: 30 Dec 2005 07:01:26 -0800
Nospam wrote:
> I am looking for examples of passing javascript source via
> html::tokeparser, has anyone seen examples using it?
Does the following help ?
#!/usr/bin/perl
# I'm assuming a javascript has the string 'javascript' in
# the 'type' or 'language' argument of its <script>-tag
# (not case sensitive).
# '<script>' with no arguments is considered as a javascript
# too (default behaviour in most browsers).
# Note: HTML::TokeParser does not support external
# script calls (<script src="..."></script>)
use strict;
use warnings;
use HTML::TokeParser;
my @scripts;
my $document = <<'HTMLFILE'
<html>
<body>
<p> aaaaa </p>
<script language="javascript">
var a = 'value'
alert(a)
</script>
<p> bbbbb </p>
<script Language='JavaScript1.5'
Type='text/javascript'>
var b = 'othervalue'
document.write(b)
</script>
<br> ccccc <br>
<script>
// nothing here
</SCRIPT>
<script
type="TEXT/JAVASCRIPT"
src="file.js">
</script>
<script language="javascript">a=0</script>
<hr color="black">
<br>
<Script Language=VBscript>
MsgBox "xxxxxxxxx", VBOKCancel
</Script>
<SCRIPT TYPE="text/javascript">
alert('yyyy')
</SCRIPT>
<!-- <script>thing</script> -->
<SCRIPT language=PerlScript>
$window->alert("01010101");
</SCRIPT>
</body>
</html>
HTMLFILE
;
my $p = HTML::TokeParser->new( \$document );
while (my $token = $p->get_tag('script'))
{
if (
($token->[1]{language}||'javascript')=~/javascript/i
&&
($token->[1]{type}||'javascript')=~/javascript/i
)
{
push @scripts, $p->get_text('/script');
}
}
# small report utility
print "\n----------------------\n".$_ for (@scripts);
--
Bart
.
- References:
- Parsing javascript with html::tokeparser
- From: Nospam
- Parsing javascript with html::tokeparser
- Prev by Date: Re: FAQ 8.3 How do I do fancy stuff with the keyboard/screen/mouse?
- Next by Date: Re: Is any diffrence in...?
- Previous by thread: Parsing javascript with html::tokeparser
- Next by thread: DateTime.pm and midnight
- Index(es):
Relevant Pages
|