docapurl 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/docapurl/browser.rb +10 -7
- data/lib/docapurl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aa0b10bd4486ba6c93c290fb5f3e0ee43197ae56c32f6c9b47352393a2f5eac
|
4
|
+
data.tar.gz: 6efd81401f6a3e631425fbced1e11bf1506b6c3e34fbb41614fb985c3a35ad7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 921bdbf8311230dabb6869115dc8a1eb34d1b820bbd348747bd77a5690a8d336270d577f71e5f36bef374bd0f9ff7ce9035711ae9b623c6e935059153cae9d45
|
7
|
+
data.tar.gz: 952f61d8f37051e404716d77fb0f1bebc80232e9bc07f616dae04183eb065a6fb84d9bd47c0bd975f45a420c9d47dc1a3a198e2f14f45e886844bdba009ab738
|
data/Gemfile.lock
CHANGED
data/lib/docapurl/browser.rb
CHANGED
@@ -4,7 +4,7 @@ require 'logger'
|
|
4
4
|
module Docapurl
|
5
5
|
class Browser
|
6
6
|
SYSTEM_MAX_PAGE_DOWN_TO_BOTTOM = 50
|
7
|
-
attr_accessor :browser, :save_path, :logger
|
7
|
+
attr_accessor :browser, :save_path, :logger, :context
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
@save_path = options[:save_path]
|
@@ -13,10 +13,12 @@ module Docapurl
|
|
13
13
|
options[:slowmo] = 0.5
|
14
14
|
@logger = options[:logger] || Logger.new(STDOUT)
|
15
15
|
@browser = Ferrum::Browser.new options
|
16
|
+
@context = browser.contexts.create
|
17
|
+
yield(self) if block_given?
|
16
18
|
end
|
17
19
|
|
18
20
|
def cap(url, options)
|
19
|
-
|
21
|
+
page = @context.create_page
|
20
22
|
options[:quality] ||= 90
|
21
23
|
options[:full] = true if options[:full].nil?
|
22
24
|
options[:path] ||= @save_path
|
@@ -25,14 +27,14 @@ module Docapurl
|
|
25
27
|
logger.info "browser begin to visit url #{url}"
|
26
28
|
|
27
29
|
set_callback("before_visit_func", options)
|
28
|
-
|
30
|
+
page.go_to(url)
|
29
31
|
set_callback("after_visit_func", options)
|
30
32
|
|
31
33
|
|
32
34
|
logger.info 'visited'
|
33
35
|
max_pagedown = options[:max_pagedown] || 5
|
34
36
|
pagedown_to_bottom = options.delete :pagedown_to_bottom
|
35
|
-
visit_whole_page(browser, max_pagedown: max_pagedown, pagedown_to_bottom: pagedown_to_bottom)
|
37
|
+
visit_whole_page(browser, page: page, max_pagedown: max_pagedown, pagedown_to_bottom: pagedown_to_bottom)
|
36
38
|
|
37
39
|
sleep_before_screen = options.delete :sleep_before_screen
|
38
40
|
logger.info "sleep #{sleep_before_screen.to_i} second before screenshot"
|
@@ -40,7 +42,7 @@ module Docapurl
|
|
40
42
|
|
41
43
|
|
42
44
|
set_callback("before_screenshot_func", options)
|
43
|
-
|
45
|
+
page.screenshot(**options)
|
44
46
|
set_callback("after_screenshot_func", options)
|
45
47
|
|
46
48
|
logger.info "screenshot ended, path = #{options[:path]}"
|
@@ -48,6 +50,7 @@ module Docapurl
|
|
48
50
|
|
49
51
|
def close
|
50
52
|
return if browser.nil?
|
53
|
+
context.dispose unless context.nil?
|
51
54
|
|
52
55
|
logger.info 'close browser'
|
53
56
|
browser.quit
|
@@ -69,10 +72,10 @@ module Docapurl
|
|
69
72
|
|
70
73
|
page_down_count.times do
|
71
74
|
logger.info "press PageDown .."
|
72
|
-
|
75
|
+
page.keyboard.type(:PageDown)
|
73
76
|
end
|
74
77
|
logger.info "press HOME .."
|
75
|
-
|
78
|
+
page.keyboard.type(:Home)
|
76
79
|
end
|
77
80
|
|
78
81
|
private
|
data/lib/docapurl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docapurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- atpking
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|