crawler 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/LICENSE +22 -0
- data/Manifest +24 -0
- data/README.rdoc +33 -0
- data/Rakefile +51 -0
- data/VERSION +1 -1
- data/crawler.gemspec +74 -0
- data/lib/crawler/webcrawler.rb +3 -0
- metadata +9 -3
data/.gitignore
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Tyler M Cunnion
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Rakefile
|
2
|
+
bin/crawler
|
3
|
+
features/step_definitions/crawler_steps.rb
|
4
|
+
features/support/env.rb
|
5
|
+
lib/crawler.rb
|
6
|
+
lib/crawler/observer.rb
|
7
|
+
lib/crawler/webcrawler.rb
|
8
|
+
spec/crawler/crawler_spec.rb
|
9
|
+
spec/crawler/observer_spec.rb
|
10
|
+
spec/fixtures/excluded/shouldnt-hit.html
|
11
|
+
spec/fixtures/exclusion.html
|
12
|
+
spec/fixtures/external.html
|
13
|
+
spec/fixtures/index.html
|
14
|
+
spec/fixtures/messed-up.html
|
15
|
+
spec/fixtures/non-html.html
|
16
|
+
spec/fixtures/non-http.html
|
17
|
+
spec/fixtures/page2.html
|
18
|
+
spec/fixtures/page3.html
|
19
|
+
spec/fixtures/page4.html
|
20
|
+
spec/fixtures/page5.html
|
21
|
+
spec/fixtures/pdf.pdf
|
22
|
+
spec/fixtures/self-reference.html
|
23
|
+
spec/spec_helper.rb
|
24
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= Crawler
|
2
|
+
|
3
|
+
Crawler consists of two classes, Crawler::Webcrawler and Crawler::Observer. All actual crawling is contained in Webcrawler, so Observer can be replaced with any class that implements the update method (See the Observable module for more).
|
4
|
+
|
5
|
+
=== Webcrawler
|
6
|
+
|
7
|
+
The Webcrawler class can be instantiated with a hash of options:
|
8
|
+
* timeout -- Time limit for the crawl operation, after which a Timeout::Error exception is raised.
|
9
|
+
* external -- Boolean; whether or not the crawler will go outside the original URI's host.
|
10
|
+
* exclude -- A URI will be excluded if it includes any of the strings within this array.
|
11
|
+
|
12
|
+
=== Observer
|
13
|
+
|
14
|
+
The Observer class may be instantiated with an object for logging, as long as it responds to the puts method. It is applied by passing an instance of it to the add_observer method of a Crawler object. Any class may be substitute (or supplement) which implements the update method with two arguments, an instance of HTTPResponse and an instance of URI.
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
gem install crawler
|
19
|
+
|
20
|
+
It's just that easy!
|
21
|
+
|
22
|
+
== Executable
|
23
|
+
|
24
|
+
The gem comes with an executable version you may find useful:
|
25
|
+
|
26
|
+
crawler url [-txl]
|
27
|
+
-t --timeout, Timeout limit in seconds
|
28
|
+
-x --exclude, Comma separated list of strings which will be passed to the exclude option of Crawler
|
29
|
+
-l --log, A filename for a log file, defaults to STDOUT
|
30
|
+
|
31
|
+
== License
|
32
|
+
|
33
|
+
This gem is licensed under the MIT/X11 license. A copy is included in the file LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'jeweler'
|
4
|
+
|
5
|
+
Jeweler::Tasks.new do |g|
|
6
|
+
g.name = "crawler"
|
7
|
+
g.summary = "Simple webcrawler"
|
8
|
+
g.description = "BFS webcrawler that implements Observable"
|
9
|
+
g.homepage = "http://github.com/tylercunnion/crawler"
|
10
|
+
g.author = "Tyler Cunnion"
|
11
|
+
g.email = "tyler.cunnion@gmail.com"
|
12
|
+
g.files.exclude 'features/**/*'
|
13
|
+
g.test_files.exclude 'features/**/*'
|
14
|
+
g.add_dependency('nokogiri')
|
15
|
+
end
|
16
|
+
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/test_*.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "crawler #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/crawler.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{crawler}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tyler Cunnion"]
|
12
|
+
s.date = %q{2010-01-25}
|
13
|
+
s.default_executable = %q{crawler}
|
14
|
+
s.description = %q{BFS webcrawler that implements Observable}
|
15
|
+
s.email = %q{tyler.cunnion@gmail.com}
|
16
|
+
s.executables = ["crawler"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"Manifest",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/crawler",
|
29
|
+
"crawler.gemspec",
|
30
|
+
"lib/crawler.rb",
|
31
|
+
"lib/crawler/observer.rb",
|
32
|
+
"lib/crawler/webcrawler.rb",
|
33
|
+
"spec/crawler/crawler_spec.rb",
|
34
|
+
"spec/crawler/observer_spec.rb",
|
35
|
+
"spec/fixtures/excluded/shouldnt-hit.html",
|
36
|
+
"spec/fixtures/exclusion.html",
|
37
|
+
"spec/fixtures/external.html",
|
38
|
+
"spec/fixtures/index.html",
|
39
|
+
"spec/fixtures/messed-up.html",
|
40
|
+
"spec/fixtures/non-html.html",
|
41
|
+
"spec/fixtures/non-http.html",
|
42
|
+
"spec/fixtures/page2.html",
|
43
|
+
"spec/fixtures/page3.html",
|
44
|
+
"spec/fixtures/page4.html",
|
45
|
+
"spec/fixtures/page5.html",
|
46
|
+
"spec/fixtures/pdf.pdf",
|
47
|
+
"spec/fixtures/self-reference.html",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
s.homepage = %q{http://github.com/tylercunnion/crawler}
|
51
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
52
|
+
s.require_paths = ["lib"]
|
53
|
+
s.rubygems_version = %q{1.3.5}
|
54
|
+
s.summary = %q{Simple webcrawler}
|
55
|
+
s.test_files = [
|
56
|
+
"spec/crawler/crawler_spec.rb",
|
57
|
+
"spec/crawler/observer_spec.rb",
|
58
|
+
"spec/spec_helper.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/lib/crawler/webcrawler.rb
CHANGED
@@ -18,6 +18,8 @@ module Crawler
|
|
18
18
|
|
19
19
|
# Accepts the following options:
|
20
20
|
# * timeout -- Time limit for the crawl operation, after which a Timeout::Error exception is raised.
|
21
|
+
# * external -- Boolean; whether or not the crawler will go outside the original URI's host.
|
22
|
+
# * exclude -- A URI will be excluded if it includes any of the strings within this array.
|
21
23
|
def initialize(options={})
|
22
24
|
@crawled = Set.new
|
23
25
|
@queue = []
|
@@ -30,6 +32,7 @@ module Crawler
|
|
30
32
|
end
|
31
33
|
|
32
34
|
# Given a URI object, the crawler will explore every linked page recursively using the Breadth First Search algorithm.
|
35
|
+
# Whenever it downloads a page, it notifies observers with an HTTPResponse subclass object and the downloaded URI object.
|
33
36
|
def crawl(start_uri)
|
34
37
|
start_uri = start_uri.normalize
|
35
38
|
@queue << start_uri
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crawler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Cunnion
|
@@ -28,12 +28,18 @@ executables:
|
|
28
28
|
- crawler
|
29
29
|
extensions: []
|
30
30
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
33
34
|
files:
|
34
35
|
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- Manifest
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
35
40
|
- VERSION
|
36
41
|
- bin/crawler
|
42
|
+
- crawler.gemspec
|
37
43
|
- lib/crawler.rb
|
38
44
|
- lib/crawler/observer.rb
|
39
45
|
- lib/crawler/webcrawler.rb
|