Created
October 26, 2015 16:53
-
-
Save ruben1/fb48a028ccdfb353fc39 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 'open-uri' | |
require 'nokogiri' | |
require 'csv' | |
url = '' | |
doc = Nokogiri::HTML(open(url)) | |
containers = doc.css('') # -> css selector for container | |
str = '' | |
containers.each do |container| | |
str << container # -> get data from each element in container | |
end | |
puts str | |
open('data.txt', 'a') do |f| | |
f << str | |
end | |
# headers = ['name', 'phone', 'email', 'address', 'postal_code', 'city', 'province', 'link'] | |
# CSV.open('third.csv', 'w') do |csv| | |
# csv << headers | |
# File.open("id.txt", "r") do |f| | |
# f.each_line do |line| | |
# line = line.strip | |
# url = 'http://www.easyfairs.com/' + line | |
# puts url | |
# begin | |
# doc = Nokogiri::HTML(open(url)) | |
# name = doc.css('h3').text.strip | |
# row = [] | |
# row << name | |
# puts row | |
# # csv << row | |
# rescue | |
# puts 'fail' | |
# end | |
# end | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment