27 lines
571 B
Ruby
27 lines
571 B
Ruby
require 'nokogiri'
|
|
require "csv"
|
|
|
|
restaurants = []
|
|
|
|
CSV.open("database.csv", "wb") do |csv|
|
|
csv << ["url", "title", "location", "address", "cuisine"]
|
|
Dir.glob("html/restaurants-*.html") do |file|
|
|
page = Nokogiri::HTML(open(file))
|
|
|
|
page.css('.plr10').each do |div|
|
|
links = div.css('a')
|
|
spans = div.css('span')
|
|
|
|
|
|
title = links[0].text
|
|
location = links[1].text
|
|
address = spans[1].text
|
|
cuisine = spans[0].text
|
|
url = links[0]['href']
|
|
|
|
csv << [url, title, location, address, cuisine]
|
|
|
|
puts url
|
|
end
|
|
end
|
|
end |