Last active
August 23, 2016 02:57
-
-
Save drakemccabe/4eb7f8ab938a8b11c7992f89e3345d32 to your computer and use it in GitHub Desktop.
Web Page to MongoDB for seeding test data
This file contains hidden or 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 '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