我正在尝试提取每天比赛的球队以及每个球队阵容中的活跃和无效球员。我要抓取的页面的URL是:https://stats.nba.com/lineups/。我一直在使用BeautifulSoup尝试获取此数据,并尝试了几种方法来获取数据,但是我似乎无法在
中提取任何内容 <div class="landing__flex-col lineups-game" data-game-state="3" nba-data-game="game" nba-with ng-include ng-repeat="game in games" src="'/lineups-template.html'">
。
我想让每场比赛中的球队
<div class="landing__flex-col lineups-game" data-game-state="3" nba-data-game="game" nba-with ng-include ng-repeat="game in games" src="'/lineups-template.html'">
,
和
中的每个玩家 <div class="columns small-6 lineups-game__team lineups-game__team--htm" nba-with nba-with-data-team="game.h" ng-include src="'/lineups-team-template.html'">
。
因此,在下面的html代码示例中,我想获取MEM,CHA,J。Valanciunas和J. Crowder的文本,并最终针对每个团队的每个球员执行此操作。
<div class="landing__flex-row lineups-games" ng-show="isLoaded && hasData" aria-hidden="false">
<!----><!----><div class="landing__flex-col lineups-game" ng-repeat="game in games" nba-with="" nba-data-game="game" data-game-state="3" ng-include="" src="'/lineups-template.html'">
<div class="lineups-game__inner row">
<div class="columns small-12 lineups-game__title">
<a href="/game/0021900154/">
<span class="lineups-game__team-name">MEM</span>
<span class="lineups-game__vs">vs</span>
<span class="lineups-game__team-name">CHA</span>
<span class="lineups-game__status hide-for-live-game">Final</span>
<span class="lineups-game__status hide-for-pre-game hide-for-post-game">Live</span>
</a>
</div>
<!----><div class="columns small-6 lineups-game__team lineups-game__team--vtm" nba-with="" nba-with-data-team="game.v" ng-include="" src="'/lineups-team-template.html'">
<!----><!----><div ng-if="team.hasBench" nba-with="" nba-with-data-team="team" ng-include="" src="'/lineups-confirmed-roster-template.html'">
<div class="lineups-game__header">
<img team-logo="" class="lineups-game__team-logo team-img" abbr="MEM" type="image/svg+xml" src="/media/img/teams/logos/MEM_logo.svg" alt="Memphis Grizzlies logo" title="Memphis Grizzlies logo">
<span class="lineups-game__team-name">MEM</span>
</div>
<div class="lineups-game__roster-type lineups-game__roster-type--confirmed">active List</div>
<ul class="lineups-game__roster lineups-game__roster--official">
<!----><li class="lineups-game__player lineups-game__player--starter" ng-repeat="pl in team.starters">
<a href="/player/202685/">
<span class="lineups-game__pos">C</span>
<span class="lineups-game__name">J. Valanciunas</span>
</a>
</li><!----><li class="lineups-game__player lineups-game__player--starter" ng-repeat="pl in team.starters">
<a href="/player/203109/">
<span class="lineups-game__pos">SF</span>
<span class="lineups-game__name">J. Crowder</span>
</a>
除其他方法外,我尝试执行以下操作无济于事:
gamesSource = urllib.request.urlopen('https://stats.nba.com/lineups/').read()
gamesSoup = bs.BeautifulSoup(gamesSource,'html.parser')
teams = gamesSoup.find_all("span",{"class":"lineups-game__teams-name"})
返回的所有内容都是一个空列表,当我尝试获取特定的“ span”行时,返回的所有内容都是“ None”。
让我知道出了什么问题,以及如何访问要获取的信息。
谢谢。