-
Notifications
You must be signed in to change notification settings - Fork 0
/
crowser.rb
executable file
·69 lines (57 loc) · 1.41 KB
/
crowser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
# vim: ft=ruby
require 'mechanize'
mechanize = Mechanize.new
# settings
login_page = 'http://login-page.com'
username_form_field = 'username'
password_form_field = 'password'
stored_hash_location = 'path/to/hash'
secrets_location = 'path/to/secrets'
navigation_path = [
{text: 'Click me'},
{text: 'And this Link...'}
]
# helper-functions
def read_file(file)
file_content = ''
File.open(file, "r") do |f|
f.each_line do |line|
file_content += line
end
end
return file_content
end
def load_user_config(file)
file_content = read_file(file)
return JSON.parse(file_content)
end
# load user-config with credentials
config = load_user_config(secrets_location)
username = config['credentialsForMyPage']['username']
password = config['credentialsForMyPage']['password']
# login
page = mechanize.get(login_page)
# name of form for login
form = page.form_with(name: 'loginform')
form[username_form_field] = username
form[password_form_field] = password
page = form.submit
navigation_path.each do |path|
link = page.link_with(path)
page = link.click
end
# get content of page
page_content = page.at('div.content').text
# hashing the content
hash = Digest::MD5.hexdigest(page_content).to_s
hash.chomp!
# get stored hash
stored_hash = read_file(stored_hash_location)
stored_hash.chomp!
# puts hash
if stored_hash == hash
puts ''
else
puts ''
end