docapurl 0.1.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a37e93ff0416e27430f0f1ac9bbd38e80a7daa206d72812066ccf6be85fa9f06
4
- data.tar.gz: 1480714897707b03fb8f15cbc4f163d2610427ec6d1e03db9f153f31074dd96d
3
+ metadata.gz: 5aa0b10bd4486ba6c93c290fb5f3e0ee43197ae56c32f6c9b47352393a2f5eac
4
+ data.tar.gz: 6efd81401f6a3e631425fbced1e11bf1506b6c3e34fbb41614fb985c3a35ad7e
5
5
  SHA512:
6
- metadata.gz: 190bbab4d71c972c0c64ce41f58b77a4beda7ee6edef06b7c66fee2313b194915dd3a026f9707113b5028f4cb16515dd1790eb150501596fade9226bcbec932e
7
- data.tar.gz: 7fccf20f97768c25ed441f48f8312422aa8dd8639300443b86ec3b46c570e261cae051281f2e5a5f1748f82881314c96d17beb72776c296f8002cdbd24548f5c
6
+ metadata.gz: 921bdbf8311230dabb6869115dc8a1eb34d1b820bbd348747bd77a5690a8d336270d577f71e5f36bef374bd0f9ff7ce9035711ae9b623c6e935059153cae9d45
7
+ data.tar.gz: 952f61d8f37051e404716d77fb0f1bebc80232e9bc07f616dae04183eb065a6fb84d9bd47c0bd975f45a420c9d47dc1a3a198e2f14f45e886844bdba009ab738
data/CH_README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Docapurl
2
2
  一个ruby的命令行截图网页的工具
3
3
 
4
+ ## 抓取网页线上服务
5
+
6
+ [https://www.urlprint.com](https://www.urlprint.com) 提供在线抓取网页生成图片的服务, 支持 REST API 调用, 欢迎各位大佬试用
7
+
4
8
  ## 安装
5
9
 
6
10
  gem install docapurl
7
11
 
12
+
8
13
  ## 前置条件
9
14
 
10
15
  - ruby 环境
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docapurl (0.1.1)
4
+ docapurl (0.2.2)
5
5
  ferrum (~> 0.11)
6
- thor (~> 0.20)
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 (0.20.3)
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", "~> 0.20"
35
+ spec.add_dependency "thor"
36
36
 
37
37
  end
@@ -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
- browser.go_to(url)
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 screen"
40
+ logger.info "sleep #{sleep_before_screen.to_i} second before screenshot"
35
41
  sleep(sleep_before_screen.to_i)
36
42
 
37
- browser.screenshot(**options)
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
- browser.keyboard.type(:PageDown)
75
+ page.keyboard.type(:PageDown)
65
76
  end
66
77
  logger.info "press HOME .."
67
- browser.keyboard.type(:Home)
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)
@@ -1,3 +1,3 @@
1
1
  module Docapurl
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.1.1
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-04-25 00:00:00.000000000 Z
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.20'
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.20'
82
+ version: '0'
83
83
  description:
84
84
  email:
85
85
  - atpking@gmail.com