Sha256: 9af28b677f5e9b3c0d2c714a5dc4b5d586dcfa58a722c45338ebe3c0a42f1e37
Contents?: true
Size: 1.01 KB
Versions: 26
Compression:
Stored size: 1.01 KB
Contents
#!/usr/bin/env ruby require 'net/http' require 'nokogiri' require 'open-uri' class Mock attr_accessor :title end counter = 0 template = ' <tr> <td> <a href="%s"> <img src="%s" width="200" /> </a> </td> <td style=""> <div> %s - <a href="%s"> %s </a> </div> </td> </tr> ' puts ' <style> td { border:solid 1px whitesmoke; } </style> ' puts '<table>' STDIN.each_line do |line| next if line.chomp == '' counter += 1 url = line.chomp begin doc = Nokogiri::HTML(open(url)) rescue => e doc = Mock.new doc.title = url end unless doc.title doc = Mock.new doc.title = url end begin image_source = '' doc.traverse do |element| break if image_source != '' if element.name == 'img' image_source = element['src'] end end rescue => error $stderr.puts error.message end bindings = [url, image_source, counter, url, doc.title] puts template % bindings end puts '</table>'
Version data entries
26 entries across 26 versions & 1 rubygems