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>
36 Webmasters can use the /robots.txt file to forbid conforming robots
37 from 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
42 /robots.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
72 following <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
84 constitutes a malformed record. This parser will assume that a
85 blank line should have been placed before that User-Agent field, and
86 will break the record into two. All the fields before the User-
87 Agent field will constitute a record, and the User-Agent field will
88 be the 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
95 Unrecognized records are ignored.
96
98 The following example "/robots.txt" file specifies that no robots
99 should visit any URL starting with "/cyberworld/map/" or "/tmp/":
100
101 User-agent: *
102 Disallow: /cyberworld/map/ # This is an infinite virtual URL space
103 Disallow: /tmp/ # these will soon disappear
104
105 This example "/robots.txt" file specifies that no robots should visit
106 any URL starting with "/cyberworld/map/", except the robot called
107 "cybermapper":
108
109 User-agent: *
110 Disallow: /cyberworld/map/ # This is an infinite virtual URL space
111
112 # Cybermapper knows where to go.
113 User-agent: cybermapper
114 Disallow:
115
116 This example indicates that no robots should visit this site further:
117
118 # go away
119 User-agent: *
120 Disallow: /
121
122 This is an example of a malformed robots.txt file.
123
124 # robots.txt for ancientcastle.example.com
125 # I've locked myself away.
126 User-agent: *
127 Disallow: /
128 # The castle is your home now, so you can go anywhere you like.
129 User-agent: Belle
130 Disallow: /west-wing/ # except the west wing!
131 # It's good to be the Prince...
132 User-agent: Beast
133 Disallow:
134
135 This file is missing the required blank lines between records.
136 However, the intention is clear.
137
139 LWP::RobotUA, WWW::RobotRules::AnyDBM_File
140
142 Copyright 1995-2009, Gisle Aas
143 Copyright 1995, Martijn Koster
144
145 This library is free software; you can redistribute it and/or modify it
146 under the same terms as Perl itself.
147
148
149
150perl v5.38.0 2023-07-21 WWW::RobotRules(3)