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

Version Path
ix-cli-0.0.27 bin/ix-linkify-html
ix-cli-0.0.26 bin/ix-linkify-html
ix-cli-0.0.25 bin/ix-linkify-html
ix-cli-0.0.24 bin/ix-linkify-html
ix-cli-0.0.23 bin/ix-linkify-html
ix-cli-0.0.22 bin/ix-linkify-html
ix-cli-0.0.21 bin/ix-linkify-html
ix-cli-0.0.20 bin/ix-linkify-html
ix-cli-0.0.19 bin/ix-linkify-html
ix-cli-0.0.18 bin/ix-linkify-html
ix-cli-0.0.17 bin/ix-linkify-html
ix-cli-0.0.16 bin/ix-linkify-html
ix-cli-0.0.15 bin/ix-linkify-html
ix-cli-0.0.14 bin/ix-linkify-html
ix-cli-0.0.13 bin/ix-linkify-html
ix-cli-0.0.12 bin/ix-linkify-html
ix-cli-0.0.11 bin/ix-linkify-html
ix-cli-0.0.10 bin/ix-linkify-html
ix-cli-0.0.9 bin/ix-linkify-html
ix-cli-0.0.7 bin/ix-linkify-html