class RaceFinder::Scraper

Public Class Methods

scrape_details(url) click to toggle source

This method is called on in the CLI based on user selection, scrapes race details: title, location, distance, highlights, and link

# File lib/race_finder/scraper.rb, line 24
def self.scrape_details(url)
        doc = Nokogiri::HTML(open(url))

        puts doc.css("#race-info").children[0..2].text
        puts doc.css("#race-info").children[3..5].text
        puts doc.css("#race-info").children[6..8].text
        puts doc.css("#race-info").children[13..15].text
        puts doc.css("#race-info").children[16..18].text
end
scrape_race_index(url) click to toggle source
# File lib/race_finder/scraper.rb, line 7
def self.scrape_race_index(url)
        doc = Nokogiri::HTML(open(url))

        rows = doc.css("table#race-finder-search-results-by-location tr")

        rows.shift

        rows[0..24].each do |row|
                race = RaceFinder::Race.new
                race.title = row.css("td.event").text
                race.location = row.css("td.city").text
                race.date = row.css("td.date").text
                race.url = row.css("td.event a").attr("href").value
        end
end