如何忽略beautifulsoup4 python上的标签

我正在做一个新项目,但我遇到了一些问题。


我的问题就是这样。


<div class="news">

      <p class="breaking">  </p>

      ...

<p> i need to pull here. </p>

但是 class = "break" 是不允许我这样做的。我想忽略“破坏”类并拉动<p>.


慕丝7291255
浏览 143回答 1
1回答

胡说叔叔

也许,class=''会做find_allor findAll:from bs4 import BeautifulSouphtml = """<div class="news">&nbsp; &nbsp; &nbsp; <p class="breaking">&nbsp; </p>&nbsp; &nbsp; &nbsp; ...<p> i need to pull here. </p>"""soup = BeautifulSoup(html, 'html.parser')print(soup.find_all('p', class_=''))print(soup.findAll(True, {'class': ''}))输出[<p> i need to pull here. </p>][<p> i need to pull here. </p>]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python