Skip to content

Instantly share code, notes, and snippets.

@rbpd5015
Created February 3, 2015 19:25
Show Gist options
  • Save rbpd5015/4e31f3a70d5f308cfae2 to your computer and use it in GitHub Desktop.
Save rbpd5015/4e31f3a70d5f308cfae2 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
static_file = "NBAtest.html"
url = "http://www.sportsbookreview.com/betting-odds/nba-basketball/"
f = open(url) { |f| f.read }
f.gsub!("½", ".5")
f.gsub!(" ", "\n")
doc = Nokogiri::HTML(f, nil, "UTF-8")
start_dates = doc.xpath('/html/head/meta[@itemprop="startdate"]/@content').collect { |node| node.value }
names = doc.xpath('/html/head/meta[@itemprop="name"]/@content').collect { |node| node.value }
urls = doc.xpath('/html/head/meta[@itemprop="url"]/@content').collect { |node| node.value }
addresses = doc.xpath('/html/head/meta[@itemprop="address"]/@content').collect { |node| node.value }
puts start_dates
games = doc.xpath('.//*[@itemtype="http://schema.org/SportsEvent"]')
games.each do |game|
game_id = game.attribute('id').value
start_date = game.attribute('rel').value
rotation = game.xpath('.//div[@class="el-div eventLine-rotation"]/*[@class="eventLine-book-value"]').collect { |node| node.text.strip }
time = game.xpath('.//*[@class="el-div eventLine-time"]').collect { |node| node.text.strip }
team_id = game.xpath('.//*[@class="team-name"]/@rel').collect { |node| node.text.strip }
teams = game.xpath('.//*[@class="el-div eventLine-team"]/*[@class="eventLine-value"]').collect { |node| node.text.strip }
tv = game.xpath('.//*[@class="el-div eventLine-tvStation"]/*[@class="eventLine-book-value"]').collect { |node| node.text.strip }
consensus = game.xpath('.//*[@class="el-div eventLine-consensus"]/text()').collect { |n| n.content }
opener = game.xpath('.//*[@class="el-div eventLine-opener"]/*[@class="eventLine-book-value"]').collect { |node| node.text.strip }
live_lines = game.xpath('.//*[@class="el-div eventLine-book"]/@rel | .//*[@class="el-div eventLine-book"]/*').collect { |node| node.text.strip }
books = game.xpath('.//*[@class="el-div eventLine-book"]')
puts game_id
puts start_date
puts names
puts urls
puts addresses
puts rotation
puts time
puts teams
puts team_id
puts tv
puts opener
puts consensus
books.each do |book|
puts book['rel']
live_lines = book.xpath('.//text()')
live_lines.each do |lines|
puts lines
end
end
puts '____________________'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment