vik-y
3/20/2016 - 4:34 PM

Script to get Live score from cricbuzz website.

Script to get Live score from cricbuzz website.

import time
import re
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}

def cleanhtml(raw_html):
  cleanr =re.compile('<.*?>')
  cleantext = re.sub(cleanr,'', raw_html)
  return cleantext
  
def liveScore():
	data = requests.get('http://push.cricbuzz.com/match-push?id=15788', headers=headers)
	# Just replace id=15788 with the match id and it will work for any cricket match. 
	#print data
	game = json.loads(data.text)
	retData = ""
	retData += game['score']['batting']['score']
	retData += "\n"
	try:
		comment = cleanhtml(game['comm_lines'][0]['comm'])
	except:
		comment = ""
	retData += comment + "\n"
	return retData


print liveScore()