COMP2021 Final Project - LightHTML

352 views

Published on

HKUST Spring 2013 COMP 2021 Unix & Script Programming
Final Project - LightHTML

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
352
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

COMP2021 Final Project - LightHTML

  1. 1. Light</HTML>
  2. 2. list - ls [options] elements
  3. 3. clean - cl elements
  4. 4. delete - de [options] elements
  5. 5. delete - de [options] elements
  6. 6. DEMO
  7. 7. Dispatch Tablehash of references to executable code
  8. 8. Dispatch Tablemy $dispatchTable = {! a => &func_a,! b => &func_b,! q => sub { exit(0) },};while ( 1 ) {! print "Press a key!n";! chomp (my $input = <STDIN>);! if (defined $dispatchTable->($input)) {! ! $dispatchTable->{$input}->();! }}Hash tableGet user inputreference to function argvs
  9. 9. Dispatch Tablemy $myFunc = {! s => &saveFile,! de => &deletTag,! cl => &cleanUp,! ls => &listTags,! q => sub { $root = $root->delete; exit(0) },! DEFAULT => sub {print ("Command not found.n")}};
  10. 10. HTML::TreeBuilderParser that builds a HTML syntax treehttp://search.cpan.org/~cjm/HTML-Tree-5.03/lib/HTML/TreeBuilder.pm
  11. 11. HTML::Treemake parse trees out ofHTML sourceHTML::TreeBuilderbuilds the parse treesHTML::Elementparse trees are made up ofelement class objects
  12. 12. create tree objectHTML::TreeBuilder#!/usr/bin/perl -wuse warnings FATAL => all;use strict;use HTML::TreeBuilder;use Term::ANSIColor;(@ARGV == 1) || exit print "Usage: [HTML file].n";(-e $ARGV[0]) || exit print "Input file does not exist.n";my $root = HTML::TreeBuilder->new;$root->parse_file($ARGV[0]) || die "$!";include module
  13. 13. htmlheadtitle metabodyph1,h2...divp p
  14. 14. Perl & LWPby Sean M. Burke"Fetching web pages, Parsing HTML,Writing Spiders, & More"http://lwp.interglacial.com/index.htmlChapter 9HTML Processing with TreesChapter 10Modifying HTML with Trees
  15. 15. Light</HTML>GitHub : LightHTMLhttps://github.com/Conrad-Lo/LightHTML

×