WWW::RobotRules - database of robots.txt-derived permissions |
WWW::RobotRules - database of robots.txt-derived permissions
use WWW::RobotRules; my $rules = WWW::RobotRules->new('MOMspider/1.0');
use LWP::Simple qw(get);
{ my $url = "http://some.place/robots.txt"; my $robots_txt = get $url; $rules->parse($url, $robots_txt) if defined $robots_txt; }
{ my $url = "http://some.other.place/robots.txt"; my $robots_txt = get $url; $rules->parse($url, $robots_txt) if defined $robots_txt; }
# Now we can check if a URL is valid for those servers # whose "robots.txt" files we've gotten and parsed: if($rules->allowed($url)) { $c = get $url; ... }
This module parses /robots.txt files as specified in ``A Standard for Robot Exclusion'', at <http://www.robotstxt.org/wc/norobots.html> Webmasters can use the /robots.txt file to forbid conforming robots from accessing parts of their web site.
The parsed files are kept in a WWW::RobotRules object, and this object provides methods to check if access to a given URL is prohibited. The same WWW::RobotRules object can be used for one or more parsed /robots.txt files on any number of hosts.
The following methods are provided:
new($robot_name)
new()
is the name of the robot.
parse()
method takes as arguments the URL that was used to
retrieve the /robots.txt file, and the contents of the file.
allowed($uri)
agent([$name])
The format and semantics of the ``/robots.txt'' file are as follows (this is an edited abstract of <http://www.robotstxt.org/wc/norobots.html> ):
The file consists of one or more records separated by one or more blank lines. Each record contains lines of the form
<field-name>: <value>
The field name is case insensitive. Text after the '#' character on a line is ignored during parsing. This is used for comments. The following <field-names> can be used:
The following example ``/robots.txt'' file specifies that no robots should visit any URL starting with ``/cyberworld/map/'' or ``/tmp/'':
User-agent: * Disallow: /cyberworld/map/ # This is an infinite virtual URL space Disallow: /tmp/ # these will soon disappear
This example ``/robots.txt'' file specifies that no robots should visit any URL starting with ``/cyberworld/map/'', except the robot called ``cybermapper'':
User-agent: * Disallow: /cyberworld/map/ # This is an infinite virtual URL space
# Cybermapper knows where to go. User-agent: cybermapper Disallow:
This example indicates that no robots should visit this site further:
# go away User-agent: * Disallow: /
the LWP::RobotUA manpage, the WWW::RobotRules::AnyDBM_File manpage
WWW::RobotRules - database of robots.txt-derived permissions |