Last active
April 2, 2022 10:03
-
-
Save olleolleolle/2e63b2f77e10d62ac944d3156a518f27 to your computer and use it in GitHub Desktop.
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
begin | |
require "nokogiri" | |
rescue LoadError | |
abort "Nokogiri not found. Oh, you may need to 'gem install nokogiri'. Quitting." | |
end | |
url = ARGV[0] | |
body = | |
if File.exists?("/tmp/body") | |
File.read("/tmp/body") | |
else | |
require 'net/http' | |
body = Net::HTTP.get(URI(url)) | |
File.write("/tmp/body", body) | |
body | |
end | |
SEEN = {} | |
doc = Nokogiri.HTML5(body) | |
doc.css("pre a[href]").each { |a| | |
image_url = a.attr("href") | |
next if SEEN[image_url] | |
image = "<p><b>#{image_url.split("/").last}</b><br><a href=#{image_url}><img src=#{image_url} width=800></a></p>" | |
a.add_previous_sibling(image) | |
SEEN[image_url] = true | |
} | |
puts doc.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment