Sha256: 8de765dbedf1dbc5d3f283496b4a084b4842030ed48859677ba26db7359e5993

Contents?: true

Size: 464 Bytes

Versions: 1

Compression:

Stored size: 464 Bytes

Contents

require 'open-uri'
require 'nokogiri'

module ImageScraper
  class Railtie < Rails::Railtie
  end

  def self.image_urls(url, convert_to_absolute_url=true)
    uri = URI.parse(url)
    domain = "#{uri.scheme}://#{uri.host}"
    doc = Nokogiri::HTML(open url)
    urls = []
    doc.xpath("//img").each do |img|
      image = img["src"]
      image = domain + image if convert_to_absolute_url and !image.include?("://")
      urls << image
    end
    urls
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
image_scraper-0.0.2 lib/image_scraper.rb