2 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
要打印表格的第一列,您可以迭代行 ( <tr>),然后獲取行 ( <td>) 的所有單元格。每行的第一個(gè)單元格是您的爵士樂(lè)流派:
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

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
您應(yīng)該閱讀 Beautifulsoup 文檔,了解如何獲取標(biāo)簽內(nèi)的屬性,如 href src 等
在這里你可以使用
item[1].get(‘title’)
- 2 回答
- 0 關(guān)注
- 187 瀏覽
添加回答
舉報(bào)