-
Notifications
You must be signed in to change notification settings - Fork 0
/
firminer.rb
45 lines (34 loc) · 1.11 KB
/
firminer.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
require "rubygems"
require "anemone"
require "fastercsv"
require "lib/crawled_record"
puts "Firminer - data miner from directory Firmy.cz"
categories = FasterCSV.read("data/categories.csv")
puts "-- read categories file -- "
categories.each do |row|
category_url = row[1].strip
category_ascii_name = category_url[/[^\/]+?$/]
file_name = "#{category_ascii_name}.csv"
begin
puts "-- crawling #{category_ascii_name} -- "
puts category_url
Anemone.crawl(category_url) do |anemone|
anemone.focus_crawl do |page|
unless page.url.to_s.include?("/detail/")
page.links.select { |link| link.to_s.include?(category_url) or link.to_s.include?("/detail/") }.reject { |link| link.to_s.include?("/reg/") }
else
[]
end
end
file = File.new("data/#{file_name}", "w")
anemone.on_pages_like(/\/detail\//) do |page|
file.puts CrawledRecord.new(page).to_csv
end
anemone.after_crawl do |pages|
puts "-- Crawled #{0} companies \n"
end
end
rescue
puts "-- #{category_ascii_name} failed to get crawled --"
end
end