micro_spider 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/micro_spider.rb +8 -0
- data/lib/spider_core/field_dsl.rb +10 -0
- data/lib/spider_core/version.rb +1 -1
- metadata +2 -2
data/lib/micro_spider.rb
CHANGED
@@ -234,6 +234,14 @@ class MicroSpider
|
|
234
234
|
excretion
|
235
235
|
end
|
236
236
|
|
237
|
+
def reset
|
238
|
+
return unless completed?
|
239
|
+
@paths = visited_paths.to_a
|
240
|
+
@excretion = { status: 'inprogress', results: [] }
|
241
|
+
@visited_paths = Set.new
|
242
|
+
@current_location = nil
|
243
|
+
end
|
244
|
+
|
237
245
|
# Spider can create custom action when it is crawling.
|
238
246
|
# @param name [String] the name of action
|
239
247
|
# @param block [Proc] the actions
|
@@ -34,6 +34,16 @@ module SpiderCore
|
|
34
34
|
fields(display, pattern, opts.merge(kind: :xpath), &block)
|
35
35
|
end
|
36
36
|
|
37
|
+
def foreach(pattern, opts = {}, &block)
|
38
|
+
return unless block_given?
|
39
|
+
kind = opts[:kind] || :css
|
40
|
+
actions << lambda {
|
41
|
+
scan_all(kind, pattern).each do |element|
|
42
|
+
yield(element)
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
37
47
|
protected
|
38
48
|
|
39
49
|
def action_for(action, action_opts = {}, opts = {}, &block)
|
data/lib/spider_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro_spider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|