Sha256: 045eeb5538689e9eeaccec38babf363540fce7be618b26a502fddd64c29dfc58
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
module Etsy4r class ImageParser attr_accessor :listing_id, :parse_url, :images def initialize(listing_id) @listing_id = listing_id @parse_url = "http://www.etsy.com/view_listing.php?listing_id=#{@listing_id}" @images = {} get_images end def get_images require 'hpricot' require 'open-uri' image_list = [] doc = open(parse_url) {|f| Hpricot(f)} img_table = doc.search("/html/body/table/tr/td/table/tr[2]/td/table/tr[3]/td/table/tr[2]/td/table/tr/td[2]/table") img_table.first.search('img').each do |img| image_list << img.attributes['src'] end image_list.each_with_index do |img_url, i| img_dom = /\/\/(\S*)\//.match(img_url)[1] img_id = /\.([\d]*)\./.match(img_url)[1] @images["#{i}"] = { "image_url_430xN" => "http://#{img_dom}/il_430xN.#{img_id}.jpg", "image_url_200x200" => "http://#{img_dom}/il_200x200.#{img_id}.jpg", "image_url_155x125" => "http://#{img_dom}/il_155x125.#{img_id}.jpg", "image_url_75x75" => "http://#{img_dom}/il_75x75.#{img_id}.jpg", "image_url_50x50" => "http://#{img_dom}/il_50x50.#{img_id}.jpg", "image_url_25x25" => "http://#{img_dom}/il_25x25.#{img_id}.jpg" } end return @images end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tcocca-etsy4r-0.1.0 | lib/etsy4r/image_parser.rb |
tcocca-etsy4r-0.2.0 | lib/etsy4r/image_parser.rb |