【发布时间】:2020-10-29 14:40:23
【问题描述】:
我是 beautifulSoup 的新手,当我想在大学课程网站上抓取一些信息时,我遇到了一个幼稚的问题。 html 如下所示,我想获取标签 p 之间的文本,而不是标签 p 之间的文本,标签 p 有一些孩子,例如<strong> and <em>
所需文字:本课程介绍......
非常感谢您的帮助!
<p>
<strong>MSDS 402 Introduction to Data Science</strong>
</p >
<p>This course introduces.....</p >
<p>
<em>Prerequisites: None.</em>
</p >
<p><a aria-label="MSDS 402-DL Section, ID#: 4765" class="link-list" href=" ">View MSDS 402-DL Sections</a ></p >
【问题讨论】:
-
Possible duplicate,试试这个
[x.string for x in soup.findAll("p") if x.string]
标签: python html beautifulsoup