Last active
February 5, 2018 00:30
-
-
Save lovasoa/483d71650e85568e3dc7824cdfb86712 to your computer and use it in GitHub Desktop.
Tennis match odds data extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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