【发布时间】:2021-10-31 10:50:38
【问题描述】:
我已经使用 BeautifulSoup 尝试了下面的解析器 html 代码。
item_detail_soup = BeautifulSoup(html, "html.parser")
h1 = item_detail_soup.find("h1")
我的 H1 解析器输出是:
<h1>
<div class="brand" style="display: block; font-size: 0.75rem;">Apple(#34567)</div>
〔NEW〕 iPhone12 256GB </h1>
我正在尝试删除这个类名为 brand 的 div。
我想要的输出:
<h1> (NEW) iPhone12 256GB </h1>
我已经尝试通过 extract() 然后替换,但我失败了。
h1 = item_detail_soup.find("h1")
h1 = h1.replace(item_detail_soup.find("h1").div.extract(),'')
我怎样才能得到我想要的输出?
【问题讨论】:
标签: python python-3.x beautifulsoup