]> gitweb.factorcode.org Git - factor.git/blob - extra/spider/spider-docs.factor
factor: trim using lists
[factor.git] / extra / spider / spider-docs.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax ;
4 IN: spider
5
6 HELP: <spider>
7 { $values
8      { "base" "a string or url" }
9      { "spider" spider } }
10 { $description "Creates a new web spider with a given base url." } ;
11
12 HELP: run-spider
13 { $values
14      { "spider" spider } }
15 { $description "Runs a spider until completion. See the " { $subsection "spider-tutorial" } " for a complete description of the tuple slots that affect how thet spider works." } ;
16
17 ARTICLE: "spider-tutorial" "Spider tutorial"
18 "To create a new spider, call the " { $link <spider> } " word with a link to the site you wish to spider."
19 { $code "\"http://concatenative.org\" <spider>" }
20 "The max-depth is initialized to 0, which retrieves just the initial page. Let's initialize it to something more fun:"
21 { $code "1 >>max-depth" }
22 "Now the spider will retrieve the first page and all the pages it links to in the same domain." $nl
23 "But suppose the front page contains thousands of links. To avoid grabbing them all, we can set " { $slot "max-count" } " to a reasonable limit."
24 { $code "10 >>max-count" }
25 "A timeout might keep the spider from hitting the server too hard:"
26 { $code "USE: calendar 1.5 seconds >>sleep" }
27 "Since we happen to know that not all pages of a wiki are suitable for spidering, we will spider only the wiki view pages, not the edit or revisions pages. To do this, we add a filter through which new links are tested; links that pass the filter are added to the todo queue, while links that do not are discarded. You can add several filters to the filter array, but we'll just add a single one for now."
28 { $code "{ [ path>> \"/wiki/view\" head? ] } >>filters" }
29 "Finally, to start the spider, call the " { $link run-spider } " word."
30 { $code "run-spider" }
31 "The full code from the tutorial."
32 { $code "USING: spider calendar sequences accessors ;
33 : spider-concatenative ( -- spider )
34     \"http://concatenative.org\" <spider>
35     1 >>max-depth
36     10 >>max-count
37     1.5 seconds >>sleep 
38     { [ path>> \"/wiki/view\" head? ] } >>filters
39     run-spider ;" } ;
40
41 ARTICLE: "spider" "Spider"
42 "The " { $vocab-link "spider" } " vocabulary implements a simple web spider for retrieving sets of webpages."
43 { $subsections "spider-tutorial" }
44 "Creating a new spider:"
45 { $subsections <spider> }
46 "Running the spider:"
47 { $subsections run-spider } ;
48
49 ABOUT: "spider"