docapurl 0.2.2 → 0.2.3
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 +4 -5
- data/lib/docapurl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b590bab2ec4319cb20309eb6a8aada80cb75f06518d3a1dc187f975a586c22
|
4
|
+
data.tar.gz: 991021e9e09e7fee0bfd2bb2c4c2de68740a6b5f21b271022b223b57876efa49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad15cf9f5f9456b163d1ca8fd6a2cab22eef9d710ad6c5acbd93609c6cd7d2f7a63e256c3875dad1312a352d0d60be5d240612e9c52e7213145ab13bae708b6d
|
7
|
+
data.tar.gz: 15c44caa1302a481166441ac3bfb43894248681c8b357752398bedaac55ab293b761d9c1ed75fe8f0c377e782b0db59e4c7f5f2373deff65e96f91e2b6957b0e
|
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, :context
|
7
|
+
attr_accessor :browser, :save_path, :logger, :context, :page
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
@save_path = options[:save_path]
|
@@ -14,11 +14,11 @@ module Docapurl
|
|
14
14
|
@logger = options[:logger] || Logger.new(STDOUT)
|
15
15
|
@browser = Ferrum::Browser.new options
|
16
16
|
@context = browser.contexts.create
|
17
|
+
@page = @context.create_page
|
17
18
|
yield(self) if block_given?
|
18
19
|
end
|
19
20
|
|
20
21
|
def cap(url, options)
|
21
|
-
page = @context.create_page
|
22
22
|
options[:quality] ||= 90
|
23
23
|
options[:full] = true if options[:full].nil?
|
24
24
|
options[:path] ||= @save_path
|
@@ -34,7 +34,7 @@ module Docapurl
|
|
34
34
|
logger.info 'visited'
|
35
35
|
max_pagedown = options[:max_pagedown] || 5
|
36
36
|
pagedown_to_bottom = options.delete :pagedown_to_bottom
|
37
|
-
visit_whole_page(
|
37
|
+
visit_whole_page(page: page, max_pagedown: max_pagedown, pagedown_to_bottom: pagedown_to_bottom)
|
38
38
|
|
39
39
|
sleep_before_screen = options.delete :sleep_before_screen
|
40
40
|
logger.info "sleep #{sleep_before_screen.to_i} second before screenshot"
|
@@ -56,8 +56,7 @@ module Docapurl
|
|
56
56
|
browser.quit
|
57
57
|
end
|
58
58
|
|
59
|
-
def visit_whole_page(
|
60
|
-
page ||= browser.page
|
59
|
+
def visit_whole_page( page: nil, max_pagedown: nil, pagedown_to_bottom: false)
|
61
60
|
viewport_height = page.viewport_size.last.to_i
|
62
61
|
document_height = page.document_size.last.to_i
|
63
62
|
return if document_height<= viewport_height
|
data/lib/docapurl/version.rb
CHANGED