Class: BoxingSchedules::Scraper
- Inherits:
-
Object
- Object
- BoxingSchedules::Scraper
- Defined in:
- lib/boxing-schedules/scraper.rb
Class Method Summary collapse
-
.open_scheduled_fights ⇒ Object
sets url for boxing schedules webpage, opens the page with Nokogiri.
-
.scrape_scheduled_fights ⇒ Object
loops through all upcoming fights on boxingscene.
Class Method Details
.open_scheduled_fights ⇒ Object
sets url for boxing schedules webpage, opens the page with Nokogiri.
4 5 6 7 |
# File 'lib/boxing-schedules/scraper.rb', line 4 def self.open_scheduled_fights url = "https://schedule.boxingscene.com/" Nokogiri::HTML(open(url)) end |
.scrape_scheduled_fights ⇒ Object
loops through all upcoming fights on boxingscene. scrapes all the fight details and sets fight attributes. saves them to the Fight class variable all.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/boxing-schedules/scraper.rb', line 13 def self.scrape_scheduled_fights content = self.open_scheduled_fights.css("div.schedules") number_of_fights = open_scheduled_fights.css(".vs").size i = 0 while i < number_of_fights fight = BoxingSchedules::Fight.new fight.channel_location = content.css("p.fight-channels")[i].text.split.join(" ") fight.fighter_names = content.css(".schedule-details-block div div")[i].text.split.join(" ").strip fight.fight_time = content.css(".schedule-time-block")[i].text.split.join(" ") fight.fight_details = content.css(".schedule-details-block")[i].text.split.join(" ") fight.fight_url = "https://schedule.boxingscene.com/" + content.css("a")[i].attr("href") fight.save i += 1 end end |