NAME

WWW::ContentRetrieval - WWW robot plus text analyzer

SYNOPSIS

  use WWW::ContentRetrieval;
  use Data::Dumper;
  $robot = WWW::ContentRetrieval->new($desc,
				 {
				     TIMEOUT    => 3,
				     HTTP_PROXY => 'http://fooproxy:2345/',
                                     DEBUG      => 1,
				 });
  print Dumper $robot->retrieve( $query );

DESCRIPTION

WWW::ContentRetrieval combines the power of a www robot and a text analyzer. It can fetch a series of web pages with some attributes in common, for example, a product catalogue. Users write down a description file and WWW::ContentRetrieval can do fetching and extract desired data. This can be applied to do price comparison or meta search, for instance.

METHODS

new

  $s = WWW::ContentRetrieval->new($desc,
			 {
			     TIMEOUT    => 3,  # default is 10 seconds.
			     HTTP_PROXY => 'http://fooproxy:2345/',
                             DEBUG      => 1,  # non-zero to print out debugging msgs
			 });

retrieve

$s->retrieve($query) returns an anonymous array of retrieved data.

You may use Data::Dumper to see it.

OTHER TOOLS

WWW::ContentRetrieval::bldTree(htmltext)

tree-ifies text. See also HTML::TreeBuilder

WWW::ContentRetrieval::genDescTmpl

automatically generates a description template.

DESC FILE TUTORIAL

OVERVIEW

Currently, this module uses native Perl's anonymous array and hash for users to write down site descriptions. Let's see an example.

Suppose the product query url of "foobar technology" be http://foo.bar/query.pl?encoding=UTF8&product=blahblahblah.

 {
   SITE  =>
   {
    NAME => "foobar tech.",
    NEXT => [
     'query.pl' => 'detail.pl',
    ],
    POLICY => [
      'http://foo.bar/detail.pl' => [
				     ["PRODUCT" => "0.1.1.0.0.5.1" ],
				     ["PRICE"   => "0.1.1.0.0.5.1.0" ],
				     ],
      'http://foo.bar/foobarproduct.pl' => \&extraction_callback,
    ],
    METHOD => 'GET',
    QHANDL => 'http://foo.bar/query.pl',
    PARAM => [
     ['encoding', 'UTF8'],
    ],
    KEY => 'product',
   }
 };

SITE

Hash key to the settings.

NAME

The name of the site.

NEXT

NEXT is an anonymous array containing pairs of (this pattern => next pattern). If the current url matches /this pattern/, then text is searched for urls that match /next pattern/ and these urls are queued for next retrieval.

POLICY

POLICY is an anonymous array containing pairs of (this pattern => node settings). If the current url matches /this pattern/, then data at the given node will be retrieved. Format of a slice is like this:

[ NODE_NAME =>
  STARTING_NODE,
  [ VARIABLE INDEX ],
  [ STEPSIZE ],
  [ ENDING ],
  [ sub{FILTER here} ]
 ]

NODE_NAME is the output key to the node data. VARIABLE INDEX is an array of integers, denoting the index numbers of individual digits in starting node at which STARTING_NODE evolves. Using Cartesian product, nodes expand one STEPSIZE one time until digits at VARIABLE INDEX are all identical to those given in ENDING.

FILTER is left to users to write callback functions handling retrieved data, such as whitespace stripping.

Except NODE_NAME and STARTING_NODE, all of them are optional.

If users append ! to the tail of STARTING_NODE, WWW::ContentRetrieval::Extract will extract the subtree hanging on the STARTING_NODE.

  • POLICY example

    [ "PRODUCT" => "0.0.0.0", [ 1, 3 ], [ 1, 2 ], [ 3, 4 ], sub { local $_ = shift; s/\s//g; $_ } ]

    Data at 0.0.0.0, 0.0.0.2, 0.0.0.4, 0.1.0.0, 0.1.0.2, 0.1.0.4, 0.2.0.0, 0.2.0.2, 0.2.0.4, 0.3.0.0, 0.3.0.2, and 0.3.0.4 will be extracted with spaces eliminated.

Also,

users may write ad hoc callback functions for extraction instead of writing down the above clumsie. WWW::ContentRetrieval passes two parameters to a callback function: a reference to page's content and page's url.

E.g.

sub my_callback{
    my ($textref, $thisurl) = @_;
    while( $$textref =~ /blahblah/g ){
         do some blahblahs here.
    }
    return an array of hashes, with keys and extracted information.
}

See also "extract.t" in t, "robot.t" in t, "recget.t" in t

METHOD

Request method: GET, POST, or PLAIN.

QHANDL

Query Handler, Url of the query script.

PARAM

Constant script parameters, without user's queries.

KEY

Key to user's query strings, e.g. product names

SEE ALSO

WWW::ContentRetrieval::Spider, WWW::ContentRetrieval::Extract

COPYRIGHT

xern <xern@cpan.org>

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.