Sha256: 24fa5ed79798865a12f0956460aecc9b079ad6039bf2688f77524fb5c61d719a
Contents?: true
Size: 524 Bytes
Versions: 1
Compression:
Stored size: 524 Bytes
Contents
require 'open-uri' require 'nokogiri' module Scrapers module Xkcd XKCD_URL = "http://xkcd.com" def self.scrape(comic=nil) results = Hash.new url = URI.parse XKCD_URL url.path = "/#{comic}/" unless comic.nil? results[:url] = url.to_s doc = Nokogiri::HTML(open(url.to_s)) comic = doc.at_css("#comic img") results[:img_src] = comic.attr("src") results[:hover_text] = comic.attr("title") results[:title] = comic.attr("alt") results end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
scrapers-0.4.0 | lib/scrapers/xkcd.rb |