docapurl 0.1.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/CH_README.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +13 -0
- data/docapurl.gemspec +1 -1
- data/lib/docapurl/browser.rb +31 -8
- data/lib/docapurl/version.rb +1 -1
- metadata +6 -6
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/CH_README.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
docapurl (0.
|
4
|
+
docapurl (0.2.2)
|
5
5
|
ferrum (~> 0.11)
|
6
|
-
thor
|
6
|
+
thor
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
34
|
rspec-support (~> 3.10.0)
|
35
35
|
rspec-support (3.10.2)
|
36
|
-
thor (
|
36
|
+
thor (1.1.0)
|
37
37
|
websocket-driver (0.7.3)
|
38
38
|
websocket-extensions (>= 0.1.0)
|
39
39
|
websocket-extensions (0.1.5)
|
data/README.md
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
A tool to screenshot the webpage on terminal.
|
4
4
|
|
5
5
|
[chinese_readme 中文说明](https://github.com/jicheng1014/docapurl/blob/master/CH_README.md)
|
6
|
+
|
7
|
+
## Capture url as a Service
|
8
|
+
|
9
|
+
[https://www.urlprint.com](https://www.urlprint.com) provides the capture url service, REST API supported.
|
10
|
+
|
11
|
+
|
12
|
+
|
6
13
|
## Installation
|
7
14
|
|
8
15
|
Add this line to your application's Gemfile:
|
@@ -37,6 +44,12 @@ use `docapurl help cap` to know more details
|
|
37
44
|
docapurl cap https:/www.bilibili.com 1.jpg --pagedown-to-bottom
|
38
45
|
```
|
39
46
|
|
47
|
+
or if u wanna know more details on screenshot
|
48
|
+
|
49
|
+
```
|
50
|
+
docapurl cap https:/www.bilibili.com 1.jpg --pagedown-to-bottom --no-headless
|
51
|
+
```
|
52
|
+
|
40
53
|
## FAQ
|
41
54
|
|
42
55
|
- Why docapurl needs chrome and where to download Chrome?
|
data/docapurl.gemspec
CHANGED
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
34
|
spec.add_dependency 'ferrum', '~>0.11'
|
35
|
-
spec.add_dependency "thor"
|
35
|
+
spec.add_dependency "thor"
|
36
36
|
|
37
37
|
end
|
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
|
@@ -24,22 +26,31 @@ module Docapurl
|
|
24
26
|
options[:path] ||= "screenshot-#{host.to_s == '' ? '' : "#{host}-"}#{Time.now.strftime('%F-%T')}.jpg"
|
25
27
|
logger.info "browser begin to visit url #{url}"
|
26
28
|
|
27
|
-
|
29
|
+
set_callback("before_visit_func", options)
|
30
|
+
page.go_to(url)
|
31
|
+
set_callback("after_visit_func", options)
|
32
|
+
|
33
|
+
|
28
34
|
logger.info 'visited'
|
29
35
|
max_pagedown = options[:max_pagedown] || 5
|
30
36
|
pagedown_to_bottom = options.delete :pagedown_to_bottom
|
31
|
-
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)
|
32
38
|
|
33
39
|
sleep_before_screen = options.delete :sleep_before_screen
|
34
|
-
logger.info "sleep #{sleep_before_screen.to_i} second before
|
40
|
+
logger.info "sleep #{sleep_before_screen.to_i} second before screenshot"
|
35
41
|
sleep(sleep_before_screen.to_i)
|
36
42
|
|
37
|
-
|
43
|
+
|
44
|
+
set_callback("before_screenshot_func", options)
|
45
|
+
page.screenshot(**options)
|
46
|
+
set_callback("after_screenshot_func", options)
|
47
|
+
|
38
48
|
logger.info "screenshot ended, path = #{options[:path]}"
|
39
49
|
end
|
40
50
|
|
41
51
|
def close
|
42
52
|
return if browser.nil?
|
53
|
+
context.dispose unless context.nil?
|
43
54
|
|
44
55
|
logger.info 'close browser'
|
45
56
|
browser.quit
|
@@ -61,12 +72,24 @@ module Docapurl
|
|
61
72
|
|
62
73
|
page_down_count.times do
|
63
74
|
logger.info "press PageDown .."
|
64
|
-
|
75
|
+
page.keyboard.type(:PageDown)
|
65
76
|
end
|
66
77
|
logger.info "press HOME .."
|
67
|
-
|
78
|
+
page.keyboard.type(:Home)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def set_callback(name, options)
|
84
|
+
the_function = options.delete name
|
85
|
+
if the_function.nil?
|
86
|
+
the_function = options.delete name.to_sym
|
87
|
+
end
|
88
|
+
|
89
|
+
the_function.call(self) unless the_function.nil?
|
68
90
|
end
|
69
91
|
|
92
|
+
|
70
93
|
class << self
|
71
94
|
def cap(url, path = nil, browser_options = {}, cap_options = {})
|
72
95
|
browser = new(browser_options)
|
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.
|
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-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: thor
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '0'
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- atpking@gmail.com
|