rcrawler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +9 -0
- data/lib/rcrawler.rb +20 -0
- data/lib/rcrawler/crawl.rb +17 -0
- data/lib/rcrawler/driver.rb +23 -0
- data/lib/rcrawler/version.rb +5 -0
- data/rcrawler.gemspec +29 -0
- data/spec/spec_helper.rb +15 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06cb51462ed7694164d649bc33f28102ae5ed66a
|
4
|
+
data.tar.gz: fc4017fd01b7140517b1e13bcbda221ac672eb77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2408c89221e3c7d4b9e6f11f1d2015d4471efe3492369ded48ba4a202fce1c30b74894201ccdd7af5cd6e94cfe8ea9090a1a11c38f3352f7929804884a7eb2a2
|
7
|
+
data.tar.gz: 6c77a1d1fab7789c3920524c746e8f1f7070a78df0b27f02a6db059eb1695a4c616389eb40939b9d6dc88d95e3ff4c7dd065b2aa01cb097ec326143612275cbe
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 i2bskn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Rcrawler
|
2
|
+
|
3
|
+
The wrapper of capybara for crawler.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rcrawler'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rcrawler
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "rcrawler"
|
23
|
+
|
24
|
+
RCrawler.crawl do
|
25
|
+
# Some capybara dsl
|
26
|
+
visit("https://example.com/login")
|
27
|
+
page.fill_in("name", with: "user")
|
28
|
+
page.fill_in("password", with: "secret")
|
29
|
+
page.click_button("send")
|
30
|
+
page.save_screenshot("/tmp/example.png")
|
31
|
+
|
32
|
+
# Screenshot shortcut
|
33
|
+
# visit(arg[0]) and page.save_screenshot(arg[1])
|
34
|
+
screenshot("http://example.com", "/tmp/example.png")
|
35
|
+
|
36
|
+
# Nokogiri
|
37
|
+
# doc is return Nokogiri::HTML(page.html)
|
38
|
+
visit("http://example.com")
|
39
|
+
doc.css("a.some_link").each {|a| puts a.attr("href")}
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rcrawler.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "capybara"
|
4
|
+
require "capybara/dsl"
|
5
|
+
require "capybara-webkit"
|
6
|
+
require "nokogiri"
|
7
|
+
require "headless"
|
8
|
+
|
9
|
+
require "rcrawler/version"
|
10
|
+
require "rcrawler/driver"
|
11
|
+
require "rcrawler/crawl"
|
12
|
+
|
13
|
+
module RCrawler
|
14
|
+
class << self
|
15
|
+
def crawl(&block)
|
16
|
+
c = Crawl.new
|
17
|
+
c.instance_eval &block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RCrawler
|
4
|
+
class Crawl < BasicObject
|
5
|
+
def initialize
|
6
|
+
@driver = Driver.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(action, *args)
|
10
|
+
if @driver.respond_to? action
|
11
|
+
@driver.send(action, *args)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RCrawler
|
4
|
+
class Driver
|
5
|
+
Capybara.default_driver = :webkit
|
6
|
+
include Capybara::DSL
|
7
|
+
attr_accessor :headless
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@headless = options.fetch(:headless, Headless.new)
|
11
|
+
@headless.start if @headless
|
12
|
+
end
|
13
|
+
|
14
|
+
def screenshot(url, file_path)
|
15
|
+
visit(url)
|
16
|
+
page.save_screenshot(file_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def doc
|
20
|
+
Nokogiri::HTML(page.html)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/rcrawler.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rcrawler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rcrawler"
|
8
|
+
spec.version = RCrawler::VERSION
|
9
|
+
spec.authors = ["i2bskn"]
|
10
|
+
spec.email = ["i2bskn@gmail.com"]
|
11
|
+
spec.description = %q{The wrapper of capybara for crawler}
|
12
|
+
spec.summary = %q{The wrapper of capybara for crawler}
|
13
|
+
spec.homepage = "https://github.com/i2bskn/rcrawler"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency "capybara"
|
26
|
+
spec.add_dependency "capybara-webkit"
|
27
|
+
spec.add_dependency "nokogiri"
|
28
|
+
spec.add_dependency "headless"
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# require "simplecov"
|
2
|
+
# require "coveralls"
|
3
|
+
# Coveralls.wear!
|
4
|
+
|
5
|
+
# SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
|
6
|
+
# SimpleCov.start do
|
7
|
+
# add_filter "spec"
|
8
|
+
# add_filter ".bundle"
|
9
|
+
# end
|
10
|
+
|
11
|
+
require "rcrawler"
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.order = "random"
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcrawler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- i2bskn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: capybara-webkit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: headless
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: The wrapper of capybara for crawler
|
112
|
+
email:
|
113
|
+
- i2bskn@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/rcrawler.rb
|
124
|
+
- lib/rcrawler/crawl.rb
|
125
|
+
- lib/rcrawler/driver.rb
|
126
|
+
- lib/rcrawler/version.rb
|
127
|
+
- rcrawler.gemspec
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: https://github.com/i2bskn/rcrawler
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.0.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: The wrapper of capybara for crawler
|
153
|
+
test_files:
|
154
|
+
- spec/spec_helper.rb
|