Skip to content

Instantly share code, notes, and snippets.

@StephenFiser
Created May 23, 2014 00:09
Show Gist options
  • Save StephenFiser/bdfd26937abe7763df15 to your computer and use it in GitHub Desktop.
Save StephenFiser/bdfd26937abe7763df15 to your computer and use it in GitHub Desktop.
require 'open-uri'
print "Enter a website domain you like (without the http://): "
website = gets.chomp
if website.count(".") >= 2
first_letter = website.index(".") + 1 # we want the letter just after the first dot
after_first_letter = first_letter + 1
last_letter = (website.index(".", after_first_letter) - 1)
website_title = website[first_letter..last_letter]
elsif website.count(".") == 1
website_title = website[0..(website.index(".") - 1)]
else
website_title = nil
end
unless website_title.nil?
file = open("http://#{website}")
contents = file.read
out_file = File.new("#{website_title}.html", "w")
out_file.puts contents
out_file.close
else
puts "We aren't sure what you did. Try again..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment