Class: ThisDayInHistory::History_Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/this_day_in_history/history_scraper.rb

Instance Method Summary collapse

Instance Method Details

#get_eventsObject



7
8
9
# File 'lib/this_day_in_history/history_scraper.rb', line 7

def get_events
  self.site_scraper.css(".day-article")
end

#make_eventsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/this_day_in_history/history_scraper.rb', line 11

def make_events    
  self.get_events.each do |e|
  if ThisDayInHistory::Events.all.none?{|event| event.title == e.css(".title").text}
 event = ThisDayInHistory::Events.new
 event.year = e.css(".year").text 
 event.title = e.css(".title").text 
 event.category = e.css(".category").text 
 event.story = e.css("p").text 
   if event.category != "Lead Story"
        event.link = e.css(".title a").attribute("href").value
        new_page = Nokogiri::HTML(open("https://www.history.com#{event.link}"))
        event.full_story = new_page.css(".article").first.text.strip
   end   
 end	
  end
end

#site_scraperObject



3
4
5
# File 'lib/this_day_in_history/history_scraper.rb', line 3

def site_scraper
  doc = Nokogiri::HTML(open('https://www.history.com/this-day-in-history'))
end