Re: Parsing javascript with html::tokeparser



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

.



Relevant Pages

  • Two Password Problems
    ... I'd try to use JavaScript to prompt for a password. ... The Java script I inserted is: ... var p=confirm("This page is for Governors only and it password protected, ...
    (comp.lang.javascript)
  • Re: Writing date and time to a document.
    ... ;-) The script does exactly what ... JavaScript guide & reference aren't bad either: ... The language attribute is deprecated, ... var timeNow = new Date; ...
    (comp.lang.javascript)
  • Re: [PHP] A two flavored post
    ... I asked this question on the javascript list, ... var someLinkHref = document.getElementById.href; ... what I needed to be in the href string. ...
    (php.general)
  • small script --> huge load --> error message
    ... I'm sure everybody who works with javascript has seen this ... A script on this page is causing mozilla to run slowly. ... way to tell a javascript to give control back to the agent interface ... var oTable, oTHead, oTBody, oTFoot, oCaption; ...
    (comp.lang.javascript)
  • VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
    ... Job is to convert that JAVASCRIPT code into SIMPLE VBA code ... Here's a bookmarklet that will tell you whether or not the browser ... JS sends request to the server (to a PHP script) ... This is the PHP script. ...
    (microsoft.public.vb.controls.internet)