-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_list.rb
54 lines (43 loc) · 922 Bytes
/
create_list.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
#!/usr/bin/ruby
require 'uri'
require 'open-uri'
require 'openssl'
require 'nokogiri'
require 'readline'
require 'optparse'
require './lib/capture_module'
# config
require './config'
# Parse CLI args
OPTS = {}
opt = OptionParser.new
opt.on('-i', '--internal-link') { |v| OPTS[:i] = v }
opt.parse!(ARGV)
data = []
File.open(ARGV[0], 'r') do |io|
while line = io.gets
data << line.chomp!
end
end
# Create anchor list
anchors = []
data.each do |uri|
html = CaptureModule.get_html(uri, OPEN_URI_OPTIONS).to_s.encode('utf-8', CHARSET)
doc = Nokogiri::HTML.parse(html)
anchors << CaptureModule.get_anchors(doc, uri, BASE_URI)
anchors << uri
end
anchors.flatten!.uniq!
targets = []
if OPTS[:i]
anchors.each do |a|
targets << a if a.match(BASE_URI)
end
else
targets = anchors
end
# Save file
File.open(OUTPUT, 'w+:utf-8') do |f|
f.puts(targets.sort!)
end
puts "Target size: #{targets.size}"