Sha256: 2fb27ae6064dc5a25107643809def4b07355d999ee688ea8fdae227502e5d99e

Contents?: true

Size: 493 Bytes

Versions: 1

Compression:

Stored size: 493 Bytes

Contents

module Rawler
  
  class Crawler
    
    attr_accessor :url, :links

    def initialize(url)
      @url = url
    end
    
    def links
      content = Net::HTTP.get(URI.parse(url))
      
      doc = Nokogiri::HTML(content)
      doc.css('a').map { |a| absolute_url(a['href']) }
    rescue Errno::ECONNREFUSED
      $output.puts "Couldn't connect to #{url}"
      []
    end
    
    private
    
    def absolute_url(path)
      URI.parse(url).merge(path.to_s).to_s
    end
  
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rawler-0.0.2 lib/rawler/crawler.rb