Class: ShootingMatchFinder::Scraper
- Inherits:
-
Object
- Object
- ShootingMatchFinder::Scraper
- Defined in:
- lib/shooting_match_finder/scraper.rb
Constant Summary collapse
- BASE_PATH =
"https://practiscore.com"
Class Method Summary collapse
-
.scrape_from_match_url(match_url) ⇒ Object
Used to add attributes to newly created match objects.
-
.scrape_matches(website_url) ⇒ Object
This creates an array of hashes that we then use to create match objects.
Class Method Details
.scrape_from_match_url(match_url) ⇒ Object
Used to add attributes to newly created match objects.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shooting_match_finder/scraper.rb', line 17 def self.scrape_from_match_url(match_url) #Used to add attributes to newly created match objects. doc = Nokogiri::HTML(open(match_url)) #This logic is used to identify matches based on whether or not registration is open, since they need to scrape differently. if !doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[1]').text.include?("Registration opens") match_info = {:match_start => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[1]/strong').text.strip, :location => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[2]').text.gsub("Location:", "").strip, :entry_fee => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/dl/dd/text()').text.strip, :description => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[3]').text} else match_info = {:match_start => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[2]/strong').text.strip, :location => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[3]').text.gsub("Location:", "").strip, :entry_fee => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/dl/dd/text()').text.strip, :description => doc.xpath('//*[@id="psMainContainer"]/div[2]/div[3]/div[1]/p[4]').text} end end |
.scrape_matches(website_url) ⇒ Object
This creates an array of hashes that we then use to create match objects.
8 9 10 11 12 13 14 15 |
# File 'lib/shooting_match_finder/scraper.rb', line 8 def self.scrape_matches(website_url) #This creates an array of hashes that we then use to create match objects. doc = Nokogiri::HTML(open(website_url)) matches = doc.css(".list-group-item") matches[0...51].collect do |match_details| {:name => match_details.css(".searchMatchWebName").text.gsub("Open", "").gsub("Closed", "").strip, :match_url => match_details.css("a").attr('href').text} end end |