Skip to content

Instantly share code, notes, and snippets.

@ruben1
Created October 26, 2015 16:53
Show Gist options
  • Save ruben1/fb48a028ccdfb353fc39 to your computer and use it in GitHub Desktop.
Save ruben1/fb48a028ccdfb353fc39 to your computer and use it in GitHub Desktop.
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