Created
February 17, 2010 15:33
-
-
Save c7/306716 to your computer and use it in GitHub Desktop.
Show all links on a page
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
def green(string) | |
"\033[0;32m#{string}\033[1;37m" | |
end | |
if !ARGV[0].nil? | |
links = Hpricot(open(ARGV[0])).search('a[@href]').map { |e| e['href'].to_s } | |
puts "###############################" | |
puts "URL: #{green ARGV[0]}" | |
puts "Link count: #{green links.count}" | |
puts "###############################" | |
puts links.join("\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment