Joseph Wang


WWW::Extractor - Semi-automated extraction of records from WWW pages


   use strict;
   use WWW::Extractor;

   my($extractor) = WWW::Extractor->new();



WWW::Extractor is a tool for semi automated extraction of records from a string containing HTML. One record within the string is marked up with extraction markups and the modules uses a pattern matching algorithm to match up the remaining records.

Extraction markup

The user markups up one record withing the HTML stream with the following symbols.


Begin a record


Begin a field named fieldname

[[[literal string]]]

This identifies a block of text that the extractor attempts to match. This string is dumped out when the records are extracted.

{{{literal string}}}

This identifies a block of text that the extractor attempts to match. This string is not dumped out when the records are extracted.


This marks an area of text that is not to be dumped out.


This ends a section of text that is not to be dumped out.


End a record.


The algorithm used is based on the edit distance wrapper generation method described in

@inproceedings{ chidlovskii00automatic, author = "Boris Chidlovskii and Jon Ragetli and Maarten de Rijke", title = "Automatic Wrapper Generation for Web Search Engines", booktitle = "Web-Age Information Management", pages = "399-410", year = "2000", url = "" }

but with two major enhancements.

1 Before calculating edit distance, the system divides the tokens into different classification groups.
2 Instead of creating a general grammar from all of the records in a file, the data extractor creates one grammar from the sample entry and then matches the rest of the text to that one grammar.



    Standard constructor


    Opens a string for processing.


    Read the next processed entry into a hash pointer.


    Closes off the string

    $self->capture($field, $regexp)

    Captures a string that is outside of an entry and inserts it into an entry hash. The routine takes two arguments. One is the field that the entry hash is to be included in. The other is the regular expression which matches the field.


    Set the debug level. Higher numbers turn on more debug levels.


    If set to one then expand out the internal A tags and IMG tags to moving the href outside the tag.


    Set to the number of tags to match at the beginning of each entry. Default is 2.


    Number of tags to match at the end of an entry, The default is 1.

    If set to one then match table tags exactly. Otherwise ignore internal table items.


The distribution contains a sample driver application and test data in the examples directory. To look at the markup for the test data, search for the (((BEGIN))) tag.

Direct mode

To run

./learn.wrapper < ./sample1.html

To run an example with --expand-hrefs

./learn.wrapper --expand-hrefs < ./sample1.html

Saving a grammar

To save off a grammar

./learn.wrapper --extract-grammar < ./sample1.html > /tmp/saved.grammar

You can then use this grammar to do future parsing

./learn.wrapper --load-grammar /tmp/saved.grammar < ./sample1.html


A wiki on this module is located at

Please contact for ideas on improvements.


Copyright (C) 2002-2004 Globewide Network Academy

Redistributed under the terms of the Lesser GNU Public License

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 94:

You can't have =items (as at line 106) unless the first thing after the =over is an =item

Around line 294:

=pod directives shouldn't be over one line long! Ignoring all 2 lines of content