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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Python/BeautifulSoup 從多個(gè) DIVS + DIV 樣式中提取文本

使用 Python/BeautifulSoup 從多個(gè) DIVS + DIV 樣式中提取文本

一只斗牛犬 2023-05-09 14:50:16
我已經(jīng)嘗試了多種解決方案來(lái)解決這個(gè)問題,但無(wú)法弄清楚我有以下 HTML:<section id="content4" class="tab-content">                                                    <p>    <div class="Text_Title">Product 1</div>    <div style="display: inline-block;">Red Ball<div></p>                                                    <p>    <div class="Text_Title">Product 2</div>    <div style="display: inline-block;">Green Ball</div></p>                                                    <p>    <div class="Text_Title">Product 3</div>    <div style="display: inline-block;">Yellow Ball</div></p>    我試圖從DIV = Text_Title和中提取文本STYLE = display: inline-block;我試圖獲得的輸出:Product 1 - Red BallProduct 2 - Green BallProduct 3 - Yellow Ball
查看完整描述

1 回答

?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

用于findAll提取符合給定條件的 Tag 對(duì)象列表,然后zip并行迭代公開迭代。

from bs4 import BeautifulSoup


input_ = """<section id="content4" class="tab-content">

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <p>

? ? <div class="Text_Title">Product 1</div>

? ? <div style="display: inline-block;">Red Ball<div></p>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <p>

? ? <div class="Text_Title">Product 2</div>

? ? <div style="display: inline-block;">Green Ball</div></p>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <p>

? ? <div class="Text_Title">Product 3</div>

? ? <div style="display: inline-block;">Yellow Ball</div></p>"""


soup = BeautifulSoup(input_, "html.parser")


for x, y in zip(soup.findAll("div", attrs={"class": "Text_Title"}),

? ? ? ? ? ? ? ? soup.findAll("div", attrs={"style": "display: inline-block;"})):

? ? print(x.text, "-", y.text)

Product 1 - Red Ball

Product 2 - Green Ball

Product 3 - Yellow Ball


查看完整回答
反對(duì) 回復(fù) 2023-05-09
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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