Skip to content

Instantly share code, notes, and snippets.

@olleolleolle
Last active April 2, 2022 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olleolleolle/2e63b2f77e10d62ac944d3156a518f27 to your computer and use it in GitHub Desktop.
Save olleolleolle/2e63b2f77e10d62ac944d3156a518f27 to your computer and use it in GitHub Desktop.
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