Skip to content

Instantly share code, notes, and snippets.

@rbpd5015
Last active August 29, 2015 14:14
Show Gist options
  • Save rbpd5015/ccabd15b7ffeb6367413 to your computer and use it in GitHub Desktop.
Save rbpd5015/ccabd15b7ffeb6367413 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!(" ", "HAHAHAHA")
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|
lines =lines.text
p begin
lines.scan(/[\d-.]+/)
rescue Exception
l = "#{$!} (#{$!.class})"
$stdout.flush
raise $!
puts l.text.split(',')
end
end
end
puts '____________________'
end
@havenwood
Copy link

:opener=>["+8.5 -110", "-8.5 -110"],
:live_lines=>
   ["123",
    "+8 -110",
    "-8 -110",
    "19",
    "",
    "",
    "238",
    "",
    "",
    "93",
    "+8 -110",
    "-8 -110",
    "1096",
    "+8 -110",
    "-8 -110",
    "169",
    "",
    "",
    "999996",
    "",
    "",
    "139",
    "",
    "",
    "999991",
    "+8 -110",
    "-8 -110",
    "999998",
    "+8 -110",
    "-8 -110"]

@rbpd5015
Copy link
Author

rbpd5015 commented Feb 3, 2015

BEFORE
["123",
"+8 -110",
"-8 -110",

AFTER
123
+8
-110
-8
-110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment