gpt4 book ai didi

python - 如何使用 BeautifulSoup 根据前一个元素获取没有 id 或 class 的

标签的内容?

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:41 25 4
gpt4 key购买 nike

我正在使用 BeautifulSoup 来抓取网页。

我试图获取没有 id 或类的 p 标签的内容,但它前面有一个具有不同类的跨度:

<p> uninteresting content here...</p>
<span class="description">DESCRIPTION:</span>
<p>Hi ! This is the content which I am interested in.</p>
<p> another uninteresting content to be discarded.</p>

那么,如何根据前面的 span class="description"获取该 p 内容?

提前致谢,

最佳答案

soup.find("span", attrs={"class": "description"}).find_next('p')

关于python - 如何使用 BeautifulSoup 根据前一个元素获取没有 id 或 class 的 <p> 标签的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44425381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com