web_stat 0.3.6 → 0.3.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ed82b635d751fd0e40eeeef77348ebfc02636f1a9f2d86ca0018c572c4b1f2d
4
- data.tar.gz: 5034dcc4ba993f6d084228eb3e7e12fe03b92e8ff9e0119d3db8f7ad81521f4a
3
+ metadata.gz: 7a94017f641fb1f84d67ea5d650c094df5a1d738ccbbf880c112f95da4a2792b
4
+ data.tar.gz: 7383ba299f9f02bae998a104e84302ea99a11a28c77ad42fa23637eec9e2a922
5
5
  SHA512:
6
- metadata.gz: d1a20f17519854baf5cea62ff55236b0ea63f9ab61b3c97df2f276ad7e64694d7d6387824957bee717c50a042734b37dcd26a6761591fa3d6550de8266454ac6
7
- data.tar.gz: 1669e18b93b126bc3d382eba1e25de554fc23751f0d51635ec42c89fa8c05392d61901bb4fa510e27b1048133e96dba153e213cab3c3de90a2af1461cca88bf2
6
+ metadata.gz: 4c7d593118d75755f3db68a9f7995de60c63c5c47ba92c30a4772bc6ade5cefda14c8b44a87475ebc6cb3ab1a0badefcd3df1f6d2038aec714af654a07c89ccd
7
+ data.tar.gz: 2aa7dc288acd6de6207ee8d3e2833ba2b480b99a6d3ffeed651cce6982bbb557adfe173dfd3af1d10345bb0ad4710f1e4b434272039bb8a988beabb35811c5b4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- web_stat (0.3.5)
4
+ web_stat (0.3.10)
5
5
  bundler (>= 2.0.2)
6
6
  cld (>= 0.8.0)
7
7
  mechanize (>= 2.7)
@@ -5,14 +5,29 @@ module WebStat
5
5
  # @param [String] url
6
6
  # @param [Integer] delay
7
7
  def get_last_url(url, delay=nil)
8
+ driver = get_driver(url, delay)
9
+ last_url = driver.current_url
10
+ driver.quit
11
+ last_url
12
+ end
13
+ # Get source of html
14
+ # @param [String] url
15
+ # @param [Integer] delay
16
+ def get_source(url, delay=nil)
17
+ driver = get_driver(url, delay)
18
+ source = driver.page_source
19
+ driver.quit
20
+ source
21
+ end
22
+
23
+ private
24
+ def get_driver(url, delay=nil)
8
25
  Selenium::WebDriver.logger.output = File.join("/tmp", "selenium.log")
9
26
  Selenium::WebDriver.logger.level = :info
10
27
  options = Selenium::WebDriver::Chrome::Options.new(args: [
11
28
  'headless',
12
29
  'no-sandbox',
13
- 'disable-gpu',
14
- 'start-maximized',
15
- 'window-size=1920,1080'
30
+ 'disable-gpu'
16
31
  ])
17
32
  driver = Selenium::WebDriver.for(:chrome, options: options)
18
33
  driver.manage.timeouts.implicit_wait = 10
@@ -21,9 +36,10 @@ module WebStat
21
36
  if delay.is_a?(Integer)
22
37
  sleep delay
23
38
  end
24
- last_url = driver.current_url
39
+ driver
40
+ rescue => e
25
41
  driver.quit
26
- last_url
42
+ raise e
27
43
  end
28
44
  end
29
45
  end
@@ -47,12 +47,9 @@ module WebStat
47
47
  break
48
48
  end
49
49
  end
50
- if path.nil?
50
+ if path.nil? || path.empty? || @nokogiri.at('body').xpath('//img').first
51
51
  path = @nokogiri.at('body').xpath('//img').first.attr('src')
52
52
  end
53
- if path.nil?
54
- Readability::Document.new(@nokogiri.at('body')).content
55
- end
56
53
  if ! path.nil? && path.match(/^\//)
57
54
  "#{URI.parse(@url).scheme}://#{URI.parse(@url).host}#{path}"
58
55
  else
@@ -81,17 +78,25 @@ module WebStat
81
78
  # @param [String] url
82
79
  # @param [String] body
83
80
  def get_url(url)
84
- agent = Mechanize.new { |_agent| _agent.user_agent = WebStat::Configure.get["user_agent"] }
81
+ mech = Mechanize.new { |_mech| _mech.user_agent = WebStat::Configure.get["user_agent"] }
85
82
  # Enable to read Robots.txt
86
- agent.robots = true
83
+ mech.robots = true
87
84
  begin
88
- document = agent.get(url, [], nil, { 'Accept-Language' => 'ja'})
89
- if document.class == Mechanize::File
90
- body = document.body
85
+ if mech.agent.robots_disallowed?(url)
86
+ raise Mechanize::RobotsDisallowedError.new(url)
87
+ end
88
+ if WebStat::Configure.get["use_chromedirver"]
89
+ body = WebStat::WebDriverHelper.get_source(url)
90
+ @status = 200
91
91
  else
92
- body = document.body.encode('UTF-8', document.encoding)
92
+ document = mech.get(url, [], nil, { 'Accept-Language' => 'ja'})
93
+ if document.class == Mechanize::File
94
+ body = document.body
95
+ else
96
+ body = document.body.encode('UTF-8', document.encoding)
97
+ end
98
+ @status = document.code
93
99
  end
94
- @status = document.code
95
100
  rescue Mechanize::ResponseCodeError => e
96
101
  body = e.page.body
97
102
  @status = e.page.code
@@ -1,3 +1,3 @@
1
1
  module WebStat
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - yusuke abe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-14 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler