web_stat 0.3.0 → 0.3.1
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/lib/helpers/web_drive_helper.rb +26 -24
- data/lib/web_stat/fetch.rb +1 -1
- data/lib/web_stat/final_redirect_url.rb +43 -43
- data/lib/web_stat/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: bf6e7c6f1461adb76d15e934bbcb4866350dbef5ee45dc36ab5bac44cac88ce5
|
4
|
+
data.tar.gz: 3f788539423a476ba805b5cc023320fbd9e16b5ef3cffe476f8c7c9a9c6bcedf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77787d2811e56d7e7db5d78c378204ff83fb44252a38c41e5843e8abf98e5c06dc5e5763f5e877202557294ea480c065f541f05ae9bd944e28433d9f46be5520
|
7
|
+
data.tar.gz: ed612a3a5bb29330c08876736e834a166f658db6f4ca75c7d93c120a60ddeb25695f98416efaeb5d42693b2278b74ca22ab83b77235135b962ce0f9ed956fd6a
|
@@ -1,28 +1,30 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
module WebStat
|
2
|
+
class WebDriverHelper
|
3
|
+
class << self
|
4
|
+
# Get last url
|
5
|
+
# @param [String] url
|
6
|
+
# @param [Integer] delay
|
7
|
+
def get_last_url(url, delay=nil)
|
8
|
+
Selenium::WebDriver.logger.output = File.join("/tmp", "selenium.log")
|
9
|
+
Selenium::WebDriver.logger.level = :info
|
10
|
+
options = Selenium::WebDriver::Chrome::Options.new(args: [
|
11
|
+
'headless',
|
12
|
+
'no-sandbox',
|
13
|
+
'disable-gpu',
|
14
|
+
'start-maximized',
|
15
|
+
'window-size=1920,1080'
|
16
|
+
])
|
17
|
+
driver = Selenium::WebDriver.for(:chrome, options: options)
|
18
|
+
driver.manage.timeouts.implicit_wait = 10
|
19
|
+
Selenium::WebDriver::Wait.new(timeout: 10)
|
20
|
+
driver.get(url)
|
21
|
+
if delay.is_a?(Integer)
|
22
|
+
sleep delay
|
23
|
+
end
|
24
|
+
last_url = driver.current_url
|
25
|
+
driver.quit
|
26
|
+
last_url
|
22
27
|
end
|
23
|
-
last_url = driver.current_url
|
24
|
-
driver.quit
|
25
|
-
last_url
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/web_stat/fetch.rb
CHANGED
@@ -122,7 +122,7 @@ module WebStat
|
|
122
122
|
# Get original url
|
123
123
|
# @param [String] url
|
124
124
|
def original_url(url)
|
125
|
-
last_url = FinalRedirectUrl.final_redirect_url(url)
|
125
|
+
last_url = WebStat::FinalRedirectUrl.final_redirect_url(url)
|
126
126
|
unless last_url.nil? || last_url.scrub('').empty?
|
127
127
|
last_url
|
128
128
|
else
|
@@ -1,50 +1,50 @@
|
|
1
1
|
# ref) https://github.com/indyarocks/final_redirect_url
|
2
2
|
# customize
|
3
3
|
# Changed
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module WebStat
|
5
|
+
class FinalRedirectUrl
|
6
|
+
class << self
|
7
|
+
def final_redirect_url(url, options={})
|
8
|
+
final_url = ''
|
9
|
+
if is_valid_url?(url)
|
10
|
+
begin
|
11
|
+
redirect_lookup_depth = options[:depth].to_i > 0 ? options[:depth].to_i : 10
|
12
|
+
response_uri = get_final_redirect_url(url, redirect_lookup_depth)
|
13
|
+
final_url = url_string_from_uri(response_uri)
|
14
|
+
rescue Exception => ex
|
15
|
+
# nothing
|
16
|
+
end
|
17
|
+
end
|
18
|
+
final_url
|
16
19
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
|
21
|
+
private
|
22
|
+
def is_valid_url?(url)
|
23
|
+
url.to_s.match? URI::regexp(['http', 'https'])
|
24
|
+
end
|
25
|
+
def get_final_redirect_url(url, limit = 10)
|
26
|
+
return url if limit <= 0
|
27
|
+
uri = URI.parse(url)
|
28
|
+
response = ::Net::HTTP.get_response(uri)
|
29
|
+
if response.class == Net::HTTPOK
|
30
|
+
return URI.parse(WebStat::WebDriverHelper.get_last_url(uri))
|
31
|
+
else
|
32
|
+
redirect_location = response['location']
|
33
|
+
location_uri = URI.parse(redirect_location)
|
34
|
+
if location_uri.host.nil?
|
35
|
+
redirect_location = uri.scheme + '://' + uri.host + redirect_location
|
36
|
+
end
|
37
|
+
warn "redirected to #{redirect_location}"
|
38
|
+
get_final_redirect_url(redirect_location, limit - 1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def url_string_from_uri(uri)
|
42
|
+
url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
|
43
|
+
if uri.fragment
|
44
|
+
url_str = url_str + "##{uri.fragment}"
|
45
|
+
end
|
46
|
+
url_str
|
37
47
|
end
|
38
|
-
warn "redirected to #{redirect_location}"
|
39
|
-
get_final_redirect_url(redirect_location, limit - 1)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.url_string_from_uri(uri)
|
44
|
-
url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
|
45
|
-
if uri.fragment
|
46
|
-
url_str = url_str + "##{uri.fragment}"
|
47
48
|
end
|
48
|
-
url_str
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
data/lib/web_stat/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|