In this Python article i want to show you How To Get Sport Live Score Results, for example you want to get the result from Cricket, Football or Basketball, so now let’s get started.
Check Python Tutorials => Python Complete Articles
OK for this purpose we are using sport.py library, it is a library for gathering live up-to-date sports scores. Baseball, basketball, cricket, football, handball, hockey, rugby, soccer, tennis, and volleyball currently functional. and it is
scrapping data from:
- scorespro.com
- pro-football-reference.com
- baseball-reference.com
- basketball-reference.com
- hockey-reference.com
First of all you need to install this library by pip like this pip install sports.py, and these are the valid sports for this library.
- Baseball:
sports.BASEBALL
- Basketball:
sports.BASKETBALL
- Cricket:
sports.CRICKET
- Football:
sports.FOOTBALL
- Handball:
sports.HANDBALL
- Hockey:
sports.HOCKEY
- Rugby Union:
sports.RUGBY_U
- Rugby League:
sports.RUGBY_L
- Soccer:
sports.SOCCER
- Tennis:
sports.TENNIS
- Volleyball:
sports.VOLLEYBALL
So now this is the complete code this article
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import sports #Live Matched all_matches = sports.all_matches() baseball = all_matches['cricket'] print(baseball) #Live Matched matches = sports.get_sport(sports.CRICKET) print(matches) #Football Live football = sports.get_sport(sports.FOOTBALL) print(football) #basketabbl basktetball = sports.get_sport(sports.BASKETBALL) print(basktetball) |
Get single match
get_match()
takes three parameters:
sport
: Name of sport being played (see above for a list of valid sports)team1
: Name of city or team in a match (Not case-sensitive)team2
: Name of city or team in a match (Not case-sensitive)
get_match()
returns a single Match object which contains the following properties:
sport
: Sport of the matchleague
: League of the matchhome_team
: Home teamaway_team
: Away teamhome_score
: Home team scoreaway_score
: Away team scorematch_time
: Current match timematch_date
: Date the match was playedmatch_link
: Link to an XML file containing match data
1 |
match = sports.get_match(sports.TENNIS, 'Murray', 'Federer') |
Get multiple matches
get_sport()
takes one parameter:
sport
: Name of sport (see above for list of valid sports)
get_sport()
returns a list of Match objects which contain the same properties described above
1 |
matches = sports.get_sport(sports.BASKETBALL) |
Get all live matches
all_matches()
returns a dictionary of Match objects grouped by sport conatining data from all live matches.
1 2 |
all_matches = sports.all_matches() baseball = all_matches['baseball'] |
Get extra team info
Only works with MLB, NBA, NFL, and NHL teams
Get team information including overall record, championships won and more.
get_team()
takes two parameters:
sport
: Sport of the team the findteam
: Name of city or team to find (Not case-sensitive)
Properties available to all valid teams/sports:
name
: Name of the teamseasons
: Total number of seasons playedrecord
: Overall regular season recordchamps
: Number of total championships (Includes pre-merger champs for NFL)leaders
: Overall team leaders for certain statistical categoriesraw
: Dictionary containing all gathered info
Properties available to only MLB teams:
pennants
: Total number of AL/NL championships
Properties available to only NFL teams:
super_bowls
: Total number of Super Bowls
Properties available to only NHL teams:
points
: Total number of regular season points earned
Properties available to both NFL/NHL teams:
playoff_record
: Overall playoff record
Properties available to MLB, NBA, NHL teams:
playoff_app
: Total number of playoff appearances
So now run the complete and this will be the result
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email