Created
January 21, 2015 22:40
-
-
Save queerviolet/8be3a8a29c49a9731270 to your computer and use it in GitHub Desktop.
ashi_browser.rb
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 '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