-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.rb
44 lines (28 loc) · 908 Bytes
/
crawl.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
# Todo:
# check for links pointing to blacklisted domains (specified in domain json?)
# check for img with src pointing to blacklisted domains
require 'anemone'
require 'json'
require 'csv'
domains = JSON.parse(File.read('./domains.json'))
results = []
lipsum_words = JSON.parse(File.read('./lib/lipsum.json'))
domains.each do |domain|
Anemone.crawl(domain) do |anemone|
anemone.on_every_page do |page|
# puts "############################"
# puts page.response_time.to_s+'|'+page.code.to_s+'|'+page.url.to_s
lipsum = !!(page.body =~ Regexp.union(lipsum_words))
# puts lipsum
# lorem_collection.each { |word| page.body.include? word }
puts page.url.to_s
row = [page.response_time, page.code, page.url.to_s, lipsum]
results << row
end
end
end
CSV.open("./output.csv", "wb") do |csv|
results.each do |r|
csv << r
end
end