如何使用BeautifulSoup在<tr>中获取特定的<td>

n1c*_*1c9 3 html python beautifulsoup

试图从nyc wiki页面的高中名单中获取所有高中名称.

我已经写了足够多的脚本来获取包含高中,学术领域和入学标准的表格标签中包含的所有信息<tr>- 但我怎样才能将其缩小到我认为可以保留的范围内td[0](吐了回来a KeyError) - 只是学校的名字?

我到目前为止编写的代码:

from bs4 import BeautifulSoup
from urllib2 import urlopen

NYC = 'https://en.wikipedia.org/wiki/List_of_high_schools_in_New_York_City'

html = urlopen(NYC)
soup = BeautifulSoup(html.read(), 'lxml')
schooltable = soup.find('table')
for td in schooltable:
    print(td)
Run Code Online (Sandbox Code Playgroud)

我收到的输出:

<tr>
    <td><a href="/wiki/The_Beacon_School" title="The Beacon School">The Beacon School</a></td>
    <td>Humanities &amp; interdisciplinary</td>
    <td>Academic record, interview</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

输出我正在寻求:

The Beacon School
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 7

如何table在页面上获得第一个,遍历所有行,除了第一个标题之外,并获取td每一行的第一个元素.适合我:

for row in soup.table.find_all('tr')[1:]:
    print(row.td.text)
Run Code Online (Sandbox Code Playgroud)