2 回答
TA贡献1815条经验 获得超13个赞
要打印表格的第一列,您可以迭代行 ( <tr>),然后获取行 ( <td>) 的所有单元格。每行的第一个单元格是您的爵士乐流派:
import requests
from bs4 import BeautifulSoup
url = 'https://en.wikipedia.org/wiki/List_of_jazz_genres'
soup = BeautifulSoup(requests.get(url).content, "html.parser")
table = soup.find_all("table")[1]
for row in table.find_all('tr')[1:]: # <-- [1:] because we don't want the header
cells = [td.get_text(strip=True) for td in row.find_all('td')]
print(cells[0])
印刷:
Acid jazz
Afro-Cuban jazz
Avant-garde jazz
Bebop
Bossa nova
British dance band
Cape jazz
Chamber jazz
Continental jazz
Cool jazz
Crossover jazz
Dark jazz/Doomjazz[1][2][3]
Dixieland
Electro Swing
Ethio jazz
Ethno jazz
European free jazz
Free funk
Free jazz
Frevo
Gypsy jazz
Hard bop
Hot club
Indo jazz
Jazz blues
Jazz-funk
Jazz fusion
Jazz rap
Jazz rock
Kansas City blues
Kansas City jazz
Latin jazz
M-Base
Mainstream jazz
Modal jazz
Neo-bop jazz
Neo-swing
Neo-bop jazz
Novelty ragtime
Nu jazz
Orchestral jazz
Post-bop
Punk jazz
Ragtime
Ska jazz
Smooth jazz
Soul jazz
Straight-ahead jazz
Stride jazz
Swing
Third stream
Trad jazz
Vocal jazz
West Coast jazz
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报