Created
February 8, 2016 15:54
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 click | |
import json | |
from livescrape import ScrapedPage, Css, CssLink, CssMulti | |
class TeamRosterPage(ScrapedPage): | |
scrape_url = 'http://stats.ncaa.org/team/roster/%(season_id)s?org_id=%(team_id)s' | |
scrape_args = ('season_id', 'team_id') | |
table_contents = CssMulti( | |
'table tbody tr', | |
jersey=Css('td:nth-child(1)'), | |
name=Css('td:nth-child(2)'), | |
position=Css('td:nth-child(3)'), | |
height=Css('td:nth-child(4)'), | |
year=Css('td:nth-child(5)'), | |
games_played=Css('td:nth-child(6)'), | |
games_started=Css('td:nth-child(7)'), | |
) | |
@click.command() | |
def main(): | |
page = TeamRosterPage(season_id='12260', team_id='328') | |
print(json.dumps(page.table_contents, indent=2)) | |
if __name__ == '__main__': | |
main() |
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
(safelead)$ python demo.py | |
[ | |
{ | |
"name": "Alexander, Cliff", | |
"year": "So", | |
"games_started": "0", | |
"height": "6-8", | |
"games_played": "0", | |
"position": "F", | |
"jersey": "02" | |
}, | |
{ | |
"name": "Bragg Jr., Carlton", | |
"year": "N/A", | |
"games_started": "0", | |
"height": "-", | |
"games_played": "23", | |
"position": "", | |
"jersey": "15" | |
}, | |
{ | |
"name": "Diallo, Cheick", | |
"year": "N/A", | |
"games_started": "1", | |
"height": "-", | |
"games_played": "17", | |
"position": "", | |
"jersey": "13" | |
}, | |
{ | |
"name": "Ellis, Perry", | |
"year": "Sr", | |
"games_started": "23", | |
"height": "6-8", | |
"games_played": "23", | |
"position": "F", | |
"jersey": "34" | |
}, | |
{ | |
"name": "Graham, Devonte'", | |
"year": "So", | |
"games_started": "22", | |
"height": "6-2", | |
"games_played": "23", | |
"position": "G", | |
"jersey": "04" | |
}, | |
{ | |
"name": "Greene, Brannen", | |
"year": "Jr", | |
"games_started": "1", | |
"height": "6-7", | |
"games_played": "17", | |
"position": "G", | |
"jersey": "14" | |
}, | |
{ | |
"name": "Lucas, Landen", | |
"year": "Jr", | |
"games_started": "5", | |
"height": "6-10", | |
"games_played": "21", | |
"position": "F", | |
"jersey": "33" | |
}, | |
{ | |
"name": "Manning, Evan", | |
"year": "Sr", | |
"games_started": "0", | |
"height": "6-3", | |
"games_played": "10", | |
"position": "G", | |
"jersey": "05" | |
}, | |
{ | |
"name": "Mason, Frank", | |
"year": "Jr", | |
"games_started": "23", | |
"height": "5-11", | |
"games_played": "23", | |
"position": "G", | |
"jersey": "0" | |
}, | |
{ | |
"name": "Mickelson, Hunter", | |
"year": "Sr", | |
"games_started": "10", | |
"height": "6-10", | |
"games_played": "19", | |
"position": "F", | |
"jersey": "42" | |
}, | |
{ | |
"name": "Mykhailiuk, Sviatoslav", | |
"year": "So", | |
"games_started": "0", | |
"height": "6-8", | |
"games_played": "21", | |
"position": "G", | |
"jersey": "10" | |
}, | |
{ | |
"name": "Oubre, Kelly", | |
"year": "So", | |
"games_started": "0", | |
"height": "6-7", | |
"games_played": "0", | |
"position": "G", | |
"jersey": "12" | |
}, | |
{ | |
"name": "Pollard, Josh", | |
"year": "So", | |
"games_started": "0", | |
"height": "6-8", | |
"games_played": "0", | |
"position": "G", | |
"jersey": "22" | |
}, | |
{ | |
"name": "Selden Jr., Wayne", | |
"year": "Jr", | |
"games_started": "23", | |
"height": "6-5", | |
"games_played": "23", | |
"position": "G", | |
"jersey": "01" | |
}, | |
{ | |
"name": "Self, Tyler", | |
"year": "Jr", | |
"games_started": "0", | |
"height": "6-2", | |
"games_played": "10", | |
"position": "G", | |
"jersey": "11" | |
}, | |
{ | |
"name": "Traylor, Jamari", | |
"year": "Sr", | |
"games_started": "7", | |
"height": "6-8", | |
"games_played": "22", | |
"position": "F", | |
"jersey": "31" | |
}, | |
{ | |
"name": "Vick, Lagerald", | |
"year": "N/A", | |
"games_started": "0", | |
"height": "-", | |
"games_played": "14", | |
"position": "", | |
"jersey": "02" | |
}, | |
{ | |
"name": "Young, Clay", | |
"year": "N/A", | |
"games_started": "0", | |
"height": "-", | |
"games_played": "7", | |
"position": "", | |
"jersey": "21" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment