module Scrapers::NasaApod
Constants
- NASA_APOD_URL
Public Instance Methods
scrape(url=nil)
click to toggle source
# File lib/scrapers/nasa_apod.rb, line 30 def scrape(url=nil) url ||= NASA_APOD_URL apod = Hash.new Mechanize.start do |m| m.get url # APOD has a funky entry page, but we want the actual page prev = m.current_page.link_with(:text => '<').href m.get prev canonical = m.current_page.link_with(:text => '>' ).href m.get canonical m.current_page.tap do |page| apod[:title] = page.title.strip apod[:link] = page.uri.to_s apod[:description] = (page/("body")).text apod[:pubDate] = page.response['date'].to_s apod[:guid] = page.uri.to_s apod[:content_encoded] = (page/("body")).to_html end end apod end