Created
December 27, 2015 13:02
-
-
Save vsvld/448a25ece2c284c4b263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
require 'csv' | |
file = File.new('sto_kyiv.csv', 'a') | |
CSV.open(file, 'w') do |csv| | |
csv << %w(name tel address) | |
1.upto(196) do |i| | |
puts i | |
html_doc = Nokogiri::HTML(open("http://www.autosite.ua/avtofirmi/sto/region_kiev/page#{i}/")) | |
firms = html_doc.css('div.firmi') | |
firms.each do |firm| | |
firm_arr = [] | |
text_tel_addr = firm.css('div.mt3').text | |
# name | |
firm_arr << firm.css('div.mt3min a').text | |
# tel | |
firm_arr << /Тел.: (.*?)\r/.match(text_tel_addr)[1] | |
# address | |
firm_arr << /Адрес: (.*?)\t/.match(text_tel_addr)[1] | |
csv << firm_arr | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment