ferrumwizard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ebfbe644929b142f88f8dc30e66db208bc8fa6c328eea266b18b6e6bf5c08da8
4
+ data.tar.gz: f5e5403ad7dc857b0086213ef42e521fb91232fd93466036d22c35d269629804
5
+ SHA512:
6
+ metadata.gz: 44ac0fdfca21e6b4bfdc42afe8bb7826de0b1df0c003b86bb19c025795633c9cad17962cd842762bb7c23c822757bd151a26dd11502015f7484f01e151d7f297
7
+ data.tar.gz: 5ac3fd607f57b5b422b2e81b32ab29106bf80691ae445dcca405808fd087718d177006c790c73956521954e306ddc2fbea9597b1790cf5049027ccca9f201f11
Binary file
Binary file
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: ferrumwizard.rb
4
+
5
+ require 'rexle'
6
+ require 'ferrum'
7
+
8
+
9
+ class FerrumWizard
10
+
11
+ attr_reader :browser, :links
12
+
13
+ def initialize(url, headless: true, debug: false)
14
+
15
+ @url, @debug = url, debug
16
+ @browser = Ferrum::Browser.new headless: headless
17
+
18
+ end
19
+
20
+ def login(username, password)
21
+
22
+ b = @browser
23
+ b.goto(@url)
24
+
25
+
26
+ # search for the username input box
27
+ e_username = b.at_xpath('//input[@type="email"]')
28
+
29
+ # search for the password input box
30
+ e_password = b.at_xpath('//input[@type="password"]')
31
+
32
+ if e_username and e_password then
33
+
34
+ e_username.focus.type(username)
35
+ e_password.focus.type(password, :Enter)
36
+
37
+ end
38
+
39
+ sleep 4
40
+ fetch_links()
41
+ self
42
+
43
+ end
44
+
45
+ def quit
46
+ @browser.quit
47
+ end
48
+
49
+ def to_rb()
50
+ end
51
+
52
+ private
53
+
54
+ def fetch_links()
55
+
56
+ b = @browser
57
+ doc = Rexle.new b.body
58
+ all_links = doc.root.xpath('//a')
59
+
60
+ valid_links = all_links.reject do |x|
61
+
62
+ puts 'x: ' + x.inspect if @debug
63
+ s = x.plaintext.gsub('&','&')
64
+ r = (x.attributes[:target] == '_blank') | s.empty?
65
+
66
+ puts 'r: ' + r.inspect if @debug
67
+ r
68
+
69
+ end.map {|x| all_links.index x}
70
+
71
+ active_links = b.xpath('//a')
72
+ valid_active_links = valid_links.map {|n| active_links[n]}
73
+
74
+
75
+ @links = valid_active_links.flat_map do |x|
76
+ a = x.text.split(/\W+/).map {|label| [label, x]} << [x.text, x]
77
+ a + a.map {|x, obj| [x.downcase, obj]}
78
+ end.to_h
79
+
80
+ names = @links.keys.map(&:downcase).uniq.select {|x| x =~ /^\w+$/}
81
+ links = @links
82
+
83
+ names.each do |name|
84
+
85
+ define_singleton_method name.to_sym do
86
+ links[name].click
87
+ sleep 3
88
+ self
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ def method_missing(method_name, *args)
96
+
97
+ node = @browser.at_css '.' + method_name.to_s
98
+ node.text if node
99
+
100
+ end
101
+
102
+ end
103
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ferrumwizard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwNzMwMTYxOTE5WhcN
15
+ MjEwNzMwMTYxOTE5WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDhNEIG
17
+ /Ab4nneih/AQFMcYk76JCiy26Xcy5uxd9ib7Emkj/9sZo6nxuSBaH03+Ixv3jgJs
18
+ TxZyaIKRsESFFmupYmKsyatCGGa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5dBEVoCWax/
34
+ IWPJE5JXx2iMvE9cWe4bFCUi7cZT7HsL6jkdUWxeTvsfc7XMbE8eWtHHiG6NjeFJ
35
+ 7e24hNRMt3t/JE9ogEO4JzFUH2vq2zzR5X9JQqEclWfwHi4cf8bZFJ7spjZQPjSZ
36
+ Ok3rs0A+kW4ixAj1rDYuoyG/
37
+ -----END CERTIFICATE-----
38
+ date: 2020-07-30 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rexle
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.5.7
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.5'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.5.7
60
+ - !ruby/object:Gem::Dependency
61
+ name: ferrum
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.9.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.9'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.9'
80
+ description:
81
+ email: james@jamesrobertson.eu
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/ferrumwizard.rb
87
+ homepage: https://github.com/jrobertson/ferrumwizard
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Makes web scraping easier using the Ferrum gem.
110
+ test_files: []
Binary file