【问题标题】:How to get the content of a <p> tag with no id or class, based on the previous element using BeautifulSoup?如何根据使用 BeautifulSoup 的前一个元素获取没有 id 或 class 的 <p> 标签的内容?
【发布时间】:2017-06-08 01:48:19
【问题描述】:

我正在使用 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 内容?

提前致谢,

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:
    soup.find("span", attrs={"class": "description"}).find_next('p')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-07
      • 2013-11-01
      • 2016-04-13
      • 2019-03-25
      • 2012-02-13
      • 2021-10-10
      • 1970-01-01
      • 2020-03-03
      相关资源
      最近更新 更多