bots 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser.rb +57 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf9bff647e8b6b3f31c1544ecfe19dfc56917b42c4fde1675a16c0b35496f3b1
|
4
|
+
data.tar.gz: 1bc18cccd443a77f1c92210700859d380c98097f34d9ce7849b628b8394fcf3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dfb77dd706a5abc384b890383d8bd8d3f77d3ea132c711f7a3980dd799055127137bd0076f1511bdb326a6a0eda9f5fbbb965b43853666c0a17407fa91bb3ca
|
7
|
+
data.tar.gz: aeecae35f0b00e8e21d819f8fed8f33e5db566a1fe7124bc2f7bde0fe39e34759c155806bb059416a78ed671dc5f4df9dade77d6c5068c6b172ab7992103b827
|
data/lib/browser.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module BlackStack
|
2
|
+
module Bots
|
3
|
+
class Browser < Watir::Browser
|
4
|
+
LOCKFILENAME = '/tmp/blackstack.bots.browser.lock'
|
5
|
+
attr_accessor :pids, :lockfile
|
6
|
+
|
7
|
+
def initialize()
|
8
|
+
self.lockfile = File.open(LOCKFILENAME, 'w+')
|
9
|
+
|
10
|
+
n = 30 # timeout in seconds
|
11
|
+
|
12
|
+
# wait the lock file /tmp/blackstack.bots.browser.lock
|
13
|
+
self.lockfile.flock(File::LOCK_EX)
|
14
|
+
begin
|
15
|
+
# get list of PID of all opened chrome browsers, before launching this one
|
16
|
+
pids_before = `pgrep -f chrome`.split("\n")
|
17
|
+
# track # of chrome processes
|
18
|
+
#print "(#{pids_before.size})"
|
19
|
+
# setup driver
|
20
|
+
client = Selenium::WebDriver::Remote::Http::Default.new
|
21
|
+
begin
|
22
|
+
client.read_timeout = n # for newest selenium webdriver version
|
23
|
+
rescue => e
|
24
|
+
client.timeout = n # deprecated in newest selenium webdriver version
|
25
|
+
end
|
26
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
27
|
+
options.add_argument('--headless')
|
28
|
+
driver = Selenium::WebDriver.for :chrome, :options => options, http_client: client
|
29
|
+
# create the browser
|
30
|
+
super(driver)
|
31
|
+
# get list of PID of all opened chrome browsers, after launching this one
|
32
|
+
pids_after = `pgrep -f chrome`.split("\n")
|
33
|
+
# store list of PID regarding this launched browser
|
34
|
+
self.pids = pids_after - pids_before
|
35
|
+
rescue => e
|
36
|
+
# unlock the file
|
37
|
+
self.lockfile.flock(File::LOCK_UN)
|
38
|
+
# raise the error
|
39
|
+
raise e
|
40
|
+
ensure
|
41
|
+
# unlock the file
|
42
|
+
self.lockfile.flock(File::LOCK_UN)
|
43
|
+
end
|
44
|
+
end # initialize
|
45
|
+
|
46
|
+
def close
|
47
|
+
# kill all pids regarding this browser
|
48
|
+
self.pids.each { |pid| `kill -9 #{pid} >/dev/null 2>&1` }
|
49
|
+
end # close
|
50
|
+
|
51
|
+
def quit
|
52
|
+
# kill all pids regarding this browser
|
53
|
+
self.pids.each { |pid| `kill -9 #{pid} >/dev/null 2>&1` }
|
54
|
+
end # quit
|
55
|
+
end # Browser
|
56
|
+
end # Bots
|
57
|
+
end # BlackStack
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
@@ -218,6 +218,7 @@ extra_rdoc_files: []
|
|
218
218
|
files:
|
219
219
|
- lib/base.rb
|
220
220
|
- lib/bots.rb
|
221
|
+
- lib/browser.rb
|
221
222
|
- lib/google.rb
|
222
223
|
- lib/indeed.rb
|
223
224
|
- lib/scraper.rb
|