Class: JPLMissions::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/jpl_missions/Scraper.rb

Class Method Summary collapse

Class Method Details

.get_page(url) ⇒ Object



3
4
5
# File 'lib/jpl_missions/Scraper.rb', line 3

def self.get_page(url)
  Nokogiri::HTML(open(url))
end

.scrape_missions_from_url(url) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jpl_missions/Scraper.rb', line 7

def self.scrape_missions_from_url(url)
  missions = []
  self.get_page(url).css("div.list_text_content").each do |mission|
    new_mission = {}
    new_mission[:title] = mission.css(".content_title").text.strip
    new_mission[:launch_date] = mission.css(".article_teaser_body").first.text
    new_mission[:description] = mission.css(".article_teaser_body").last.text.strip
    missions << new_mission
  end

  missions
end