示例#1
0
def getInjuredPlayers():
    projURL = "http://www.rotowire.com/basketball/nba_lineups.htm"
    # projURL = "http://www.rotowire.com/basketball/nba_lineups.htm?date=tomorrow"
    projPage = requests.get(projURL)
    projTree = html.fromstring(projPage.content)


    awayTeamNames = projTree.xpath("//div[@class='span15 dlineups-mainbox']/div[@class='span15 dlineups-mainbar']/div[@class='dlineups-mainbar-away']/a/text()")
    # print(awayTeamNames)

    homeTeamNames = projTree.xpath("//div[@class='span15 dlineups-mainbox']/div[@class='span15 dlineups-mainbar']/div[@class='dlineups-mainbar-home']/a/text()")
    # print(homeTeamNames)


    injuredMap = {}

    for awayTeamName in awayTeamNames:
        teamNum = Util.team_dict[awayTeamName]
        injuredNameList = projTree.xpath("//div[div/div/a = '" + awayTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/a/text()")
        injuredURLList = projTree.xpath("//div[div/div/a = '" + awayTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/a/@href")
        injuredURLList = ["http://www.rotowire.com" + x for x in injuredURLList]
        injuredDesignationList = projTree.xpath("//div[div/div/a = '" + awayTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/b/text()")
        finalList = [x[0] for x in zip(Util.convertRotowireList(injuredNameList,injuredURLList),injuredDesignationList) if x[1] != "inactive"]
        injuredMap[teamNum] = finalList


    for homeTeamName in homeTeamNames:
        teamNum = Util.team_dict[homeTeamName]
        injuredNameList = projTree.xpath("//div[div/div/a = '" + homeTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/a/text()")
        injuredURLList = projTree.xpath("//div[div/div/a = '" + homeTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/a/@href")
        injuredURLList = ["http://www.rotowire.com" + x for x in injuredURLList]
        injuredDesignationList = projTree.xpath("//div[div/div/a = '" + homeTeamName + "']/div[@class='span15']/div[@class='span15']/div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/text()")
        finalList = [x[0] for x in zip(Util.convertRotowireList(injuredNameList,injuredURLList),injuredDesignationList) if x[1] != "inactive"]
        injuredMap[teamNum] = finalList


    # injuredNameList = projTree.xpath("//div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/a/text() | //div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/a/text()")
    #
    # injuredURLList = projTree.xpath("//div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/a/@href | //div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/a/@href")
    # injuredURLList = ["http://www.rotowire.com" + x for x in injuredURLList]

    # injuredDesignationList = projTree.xpath("//div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/b/text() | //div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/b/text() | //div[@class='dlineups-half equalheight']/div[@class='dlineups-vplayer']/div/text() | //div[@class='dlineups-half equalheight']/div[@class='dlineups-hplayer']/div/text()")

    #print(injuredDesignationList)



    return injuredMap
示例#2
0
def getProjStarters():
    projURL = "http://www.rotowire.com/basketball/nba_lineups.htm"
    projPage = requests.get(projURL)
    projTree = html.fromstring(projPage.content)


    starterNameList = projTree.xpath("//div[@class='dlineups-half']/div[@class='dlineups-vplayer']/div/a/text() | //div[@class='dlineups-half']/div[@class='dlineups-hplayer']/div/a/text()")


    starterURLList = projTree.xpath("//div[@class='dlineups-half']/div[@class='dlineups-vplayer']/div/a/@href | //div[@class='dlineups-half']/div[@class='dlineups-hplayer']/div/a/@href")


    starterURLList = ["http://www.rotowire.com" + x for x in starterURLList]


    #print(starterFullURLList)

    #starterNameList = [(html.fromstring(requests.get(x).content)).xpath("//h1[position()=1]/text()")[0] for x in starterFullURLList]
    #print(starterNameList)


    return Util.convertRotowireList(starterNameList,starterURLList)