Error processing SSI file
Error processing SSI file

Home » Development Area » DigiGuide Listings Grabber » API Index » Class: HTMLParser

Class: HTMLParser


Summary

Allows easy HTML parsing with callbacks


Methods

MethodDescription
 Constructor Creates an HTMLParser object.
 parse Parse the HTML. Can pass a string to control which tags you get callbacks for.


Events

EventDescription
 onEndDoc Called when the end of the document has been reached.
 onGotComment Called when the parser comes across an HTML comment.
 onGotEndTag Called when he parser comes across an end tag.
 onGotTag Called whenever the parser comes across a tag.
 onGotText Called when the parser has some text from between the tags


Examples

var g = new Grabber( "Grabber Test HTML Parser", "GBR" );

g.onRun = function( lp )
{
this.test = "my test variable in grabber object";

var hp = new HTMLParser( "<body onload=\"\"><img src=\"ignored\" /><p align=\"center\" align=\"middle\">nonsense<span class=\"bold\" align=\"center\">this is <!-- a bit of a comment --> some text</span></p></body>" );
hp.m_grabber = this;
hp.m_lp = lp;

hp.onGotTag = function( tag, params )
{
var paramList = "";

if( params.align )
{
if( typeof params.align == "object" )
{
for( var n = 0; n < params.align.length; n++ )
{
paramList += " align[" + n + "]=" + params.align[ n ] + ",";
}
}
else
{
paramList += " align=" + params.align + ",";
}
}

this.m_lp.writeLog( "Found tag: " + tag + paramList );
}

hp.onGotEndTag = function( tag )
{
this.m_lp.writeLog( "Found end tag: " + tag );
}

hp.onGotText = function( text )
{
this.m_lp.writeLog( "Found text: " + text );
}

hp.onEndDoc = function()
{
this.m_lp.writeLog( "Finished" );
}


hp.onGotComment = function( text )
{
this.m_lp.writeLog( "Found comment: " + text );
this.m_lp.writeLog( "Accessing test variable: " + this.m_grabber.test );
}

hp.parse( "body span a p div" );

return false;
}


Requirements

Build Build 3

(Last updated: February 13, 2020 12:43:30)

Error processing SSI file