1WWW::RobotRules(3) User Contributed Perl Documentation WWW::RobotRules(3)
2
3
4
6 WWW::RobotRules - database of robots.txt-derived permissions
7
9 use WWW::RobotRules;
10 my $rules = WWW::RobotRules->new('MOMspider/1.0');
11
12 use LWP::Simple qw(get);
13
14 {
15 my $url = "http://some.place/robots.txt";
16 my $robots_txt = get $url;
17 $rules->parse($url, $robots_txt) if defined $robots_txt;
18 }
19
20 {
21 my $url = "http://some.other.place/robots.txt";
22 my $robots_txt = get $url;
23 $rules->parse($url, $robots_txt) if defined $robots_txt;
24 }
25
26 # Now we can check if a URL is valid for those servers
27 # whose "robots.txt" files we've gotten and parsed:
28 if($rules->allowed($url)) {
29 $c = get $url;
30 ...
31 }
32
34 This module parses /robots.txt files as specified in "A Standard for
35 Robot Exclusion", at <http://www.robotstxt.org/wc/norobots.html> Web‐
36 masters can use the /robots.txt file to forbid conforming robots from
37 accessing parts of their web site.
38
39 The parsed files are kept in a WWW::RobotRules object, and this object
40 provides methods to check if access to a given URL is prohibited. The
41 same WWW::RobotRules object can be used for one or more parsed /ro‐
42 bots.txt files on any number of hosts.
43
44 The following methods are provided:
45
46 $rules = WWW::RobotRules->new($robot_name)
47 This is the constructor for WWW::RobotRules objects. The first
48 argument given to new() is the name of the robot.
49
50 $rules->parse($robot_txt_url, $content, $fresh_until)
51 The parse() method takes as arguments the URL that was used to
52 retrieve the /robots.txt file, and the contents of the file.
53
54 $rules->allowed($uri)
55 Returns TRUE if this robot is allowed to retrieve this URL.
56
57 $rules->agent([$name])
58 Get/set the agent name. NOTE: Changing the agent name will clear
59 the robots.txt rules and expire times out of the cache.
60
62 The format and semantics of the "/robots.txt" file are as follows (this
63 is an edited abstract of <http://www.robotstxt.org/wc/norobots.html> ):
64
65 The file consists of one or more records separated by one or more blank
66 lines. Each record contains lines of the form
67
68 <field-name>: <value>
69
70 The field name is case insensitive. Text after the '#' character on a
71 line is ignored during parsing. This is used for comments. The fol‐
72 lowing <field-names> can be used:
73
74 User-Agent
75 The value of this field is the name of the robot the record is
76 describing access policy for. If more than one User-Agent field is
77 present the record describes an identical access policy for more
78 than one robot. At least one field needs to be present per record.
79 If the value is '*', the record describes the default access policy
80 for any robot that has not not matched any of the other records.
81
82 The User-Agent fields must occur before the Disallow fields. If a
83 record contains a User-Agent field after a Disallow field, that con‐
84 stitutes a malformed record. This parser will assume that a blank
85 line should have been placed before that User-Agent field, and will
86 break the record into two. All the fields before the User-Agent
87 field will constitute a record, and the User-Agent field will be the
88 first field in a new record.
89
90 Disallow
91 The value of this field specifies a partial URL that is not to be
92 visited. This can be a full path, or a partial path; any URL that
93 starts with this value will not be retrieved
94
96 The following example "/robots.txt" file specifies that no robots
97 should visit any URL starting with "/cyberworld/map/" or "/tmp/":
98
99 User-agent: *
100 Disallow: /cyberworld/map/ # This is an infinite virtual URL space
101 Disallow: /tmp/ # these will soon disappear
102
103 This example "/robots.txt" file specifies that no robots should visit
104 any URL starting with "/cyberworld/map/", except the robot called
105 "cybermapper":
106
107 User-agent: *
108 Disallow: /cyberworld/map/ # This is an infinite virtual URL space
109
110 # Cybermapper knows where to go.
111 User-agent: cybermapper
112 Disallow:
113
114 This example indicates that no robots should visit this site further:
115
116 # go away
117 User-agent: *
118 Disallow: /
119
120 This is an example of a malformed robots.txt file.
121
122 # robots.txt for ancientcastle.example.com
123 # I've locked myself away.
124 User-agent: *
125 Disallow: /
126 # The castle is your home now, so you can go anywhere you like.
127 User-agent: Belle
128 Disallow: /west-wing/ # except the west wing!
129 # It's good to be the Prince...
130 User-agent: Beast
131 Disallow:
132
133 This file is missing the required blank lines between records. How‐
134 ever, the intention is clear.
135
137 LWP::RobotUA, WWW::RobotRules::AnyDBM_File
138
139
140
141perl v5.8.8 2004-04-06 WWW::RobotRules(3)