1 回答

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
添加回答
舉報(bào)