Skip to content

Instantly share code, notes, and snippets.

@queerviolet
Created January 21, 2015 22:40
Show Gist options
  • Save queerviolet/8be3a8a29c49a9731270 to your computer and use it in GitHub Desktop.
Save queerviolet/8be3a8a29c49a9731270 to your computer and use it in GitHub Desktop.
ashi_browser.rb
require 'open-uri'
require 'nokogiri'
url = ARGV[0]
while true
puts '******************************************'
puts "ashibrowse v.0.0000001 — Retrieving #{url}"
body = open(url).read
doc = Nokogiri::HTML(body)
puts "Title: #{doc.title}"
links = doc.search('a[href]')
links.each_with_index do |a, i|
puts "[#{i}] #{a.text} -- #{a.attr('href')}"
end
i = STDIN.gets.chomp.to_i
relative_url = links[i].attr('href').to_s
if not relative_url =~ /^http/
url = "#{url}/#{relative_url}"
else
url = relative_url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment