Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
Last active August 23, 2016 02:57
Show Gist options
  • Save drakemccabe/4eb7f8ab938a8b11c7992f89e3345d32 to your computer and use it in GitHub Desktop.
Save drakemccabe/4eb7f8ab938a8b11c7992f89e3345d32 to your computer and use it in GitHub Desktop.
Web Page to MongoDB for seeding test data
require 'nokogiri'
require 'open-uri'
require 'mongo'
x = true
while x
content = ""
puts "enter site"
site = gets.chomp
doc = Nokogiri::HTML(open(site))
doc.css('#main-content').each do|n|
content = n.inner_html
end
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'mydb')
result = client[:pages].insert_one({ pageId: rand(999), contents: content })
puts result.n
puts "go again?"
go_again = gets.chomp
if go_again.downcase == "no" || go_again.downcase == "exit"
break
else
x = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment