Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active February 5, 2018 00:30
Show Gist options
  • Save lovasoa/483d71650e85568e3dc7824cdfb86712 to your computer and use it in GitHub Desktop.
Save lovasoa/483d71650e85568e3dc7824cdfb86712 to your computer and use it in GitHub Desktop.
Tennis match odds data extraction
#!/bin/env python3
from urllib.request import *
from urllib.parse import unquote
import json
import re
from pprint import pprint
match_url="http://www.oddsportal.com/tennis/france/french-open-mixed-doubles/groenefeld-anna-lena-farah-robert-dabrowski-gabriela-bopanna-rohan-Iqu25RYO/"
res=urlopen(match_url).read().decode("utf-8")
jsoncode=re.search(r"PageEvent\((.*?)\)", res).group(1)
pagedata=json.loads(jsoncode)
url='http://fb.oddsportal.com/feed/match/{versionId}-{sportId}-{id}-3-2-{rawhash}.dat'.format(**pagedata, rawhash=unquote(pagedata['xhash']))
req=Request(url, headers={"Referer":match_url})
oddstxt=urlopen(req).read().decode('utf-8')
odds=json.loads(re.search(r'\{.*\}', oddstxt).group(0))
pprint(odds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment