Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
Created October 4, 2013 21:31
Show Gist options
  • Select an option

  • Save ivanbrennan/6833105 to your computer and use it in GitHub Desktop.

Select an option

Save ivanbrennan/6833105 to your computer and use it in GitHub Desktop.
Scrape-to-db
require "open-uri"
require "Nokogiri"
require "sqlite3"
def create_db
schema = students.first.keys.join(", ")
rows = db.execute <<-SQL
create table students (
schema
);
SQL
end
def parse_profile(profile_url)
profile_page = Nokogiri::HTML(open(profile_url))
# Insert data
students_arr.each do |student_hash|
student_hash.each do |pair|
db.execute "insert into students values ( ?, ?)", pair
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment