2 回答

TA貢獻1836條經(jīng)驗 獲得超4個贊
soup=BeautifulSoup('<tr align="center" height="15" id="tr_1599656" bgcolor="#ffffff" index="0"></tr><tr align="center" height="15" id="tr_1599657" bgcolor="#ffffff" index="1"></tr><tr align="center" height="15" id="tr_1599644" bgcolor="#ffffff" index="2"></tr>')
lines=soup.find_all('tr')
for line in lines:print(re.findall('\d+',line['id'])[0])
請下次自行嘗試一次。

TA貢獻1784條經(jīng)驗 獲得超7個贊
假設(shè)所有id屬性都遵循模式tr_XXXXXXX。此代碼將適用于它
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_code,'html.parser')
for t in soup.findAll('tr'):
print(t['id'][3:])
輸出
1599656
1599657
1599644
變量html_code包含您在問題中發(fā)布的一段html代碼
添加回答
舉報