Skip to content

Instantly share code, notes, and snippets.

@5nyper
Last active August 29, 2015 14:11
Show Gist options
  • Save 5nyper/e87095b406bd538fb89d to your computer and use it in GitHub Desktop.
Save 5nyper/e87095b406bd538fb89d to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'open_uri_redirections'
puts "Enter URL to parse HTML: "
url = gets.chomp
puts "Enter tag to parse from: "
tag = gets.chomp
response = open(url,:allow_redirections => :safe).read
title1 = response.index(tag)
title2 = response.index(tag.insert(1,'/')) -1
result = response[(title1 + tag.length - 1)..title2]
print result
ERROR: /usr/local/rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- open_uri_redirections (LoadError)
from /usr/local/rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/workspace/htmlparse.rb:2:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment