Class: RaceFinder::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/race_finder/scraper.rb

Class Method Summary collapse

Class Method Details

.scrape_details(url) ⇒ Object

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



24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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