Created
March 20, 2016 16:34
-
-
Save vik-y/7f302932de742abaaf01 to your computer and use it in GitHub Desktop.
Script to get Live score from cricbuzz website.
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
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use it plz tell me.