擅长:python、mysql、java
<p>如果你想要的只是先发球员,那就相当直接了,只要在<em>分区内容隐藏-测试</em>并从<em>中提取文本td.名称</em>标签:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
teams = {}
page = requests.get('http://espn.go.com/nba/boxscore?gameId=400827888')
soup = BeautifulSoup(page.content)
for table in soup.select("div.content.hide-bench"):
team = table.select_one("div.table-caption").find(text=True)
teams[team] = [tr.select_one("td.name").text for tr in table.find("tbody").find_all("tr")]
from pprint import pprint as pp
pp(teams)
</code></pre>
<p>这给了你:</p>
<pre><code>{'Hawks': ['P. MillsapPF',
'K. BazemoreSF',
'A. HorfordC',
'J. TeaguePG',
'K. KorverSG'],
'Pistons': ['M. MorrisPF',
'E. IlyasovaPF',
'A. DrummondC',
'R. JacksonPG',
'K. Caldwell-PopeSG']}
</code></pre>