第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過beautifulsoup獲得以下HTML標(biāo)記內(nèi)的數(shù)字?

通過beautifulsoup獲得以下HTML標(biāo)記內(nèi)的數(shù)字?

守候你守候我 2021-05-06 07:11:59
我可以通過beautifulsoup在以下HTML標(biāo)簽中獲取數(shù)字嗎?<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>我嘗試過的Python代碼from bs4 import BeautifulSoupimport rehtml_code = """"<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>"""soup = BeautifulSoup(html_code,'html.parser')rows = soup.findAll("tr", {"id" : re.compile('tr_*\d')})print rows預(yù)期產(chǎn)量159965615996571599644
查看完整描述

2 回答

?
HUH函數(shù)

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])

請下次自行嘗試一次。


查看完整回答
反對 回復(fù) 2021-05-25
?
嚕嚕噠

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代碼




查看完整回答
反對 回復(fù) 2021-05-25
  • 2 回答
  • 0 關(guān)注
  • 232 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號