在a";“类”;python中HTML中的属性?

在a";“类”;python中HTML中的属性?,python,html,beautifulsoup,Python,Html,Beautifulsoup,我有一个网站的HTML字符串。下面是其中的一部分 <p class="news-body"> <a href="/ci/content/player/45568.html" target="new">Paul Harris,</a> the South African spinner, is to retire at the end of the season, bringing to an end a 14-year first-class career.

我有一个网站的HTML字符串。下面是其中的一部分

<p class="news-body">
<a href="/ci/content/player/45568.html" target="new">Paul Harris,</a> the South African spinner, is to retire at the end of the season, bringing to an end a 14-year first-class career.
</p>
<p class="news-body">
 Harris played 37 Tests for South Africa with his slow-left arm but nearly turned his back on international cricket after a stint as a Kolpak with Warwickshire in 2006. The retirement of Nicky Boje prompted Harris' eventual call-up and he went on to take 103 wickets at 37.87.
</p>
<p class="news-body">
His last Test was in Cape Town against India in January 2011 after which he was dropped for legspinner Imran Tahir. As recently as the start of this season he indicated his intention to compete for a Test place once again.
</p>  </div>
   <!-- body area ends here  -->
不幸的是,上面只返回第一行,即:

Paul Harris,the South African spinner, is to retire at the end of the season, bringing to an end a 14-year first-class career.

我希望它返回所有文本。

find
仅查找第一个元素。您需要
findAll
,它将返回元素列表

您可以按如下方式将它们的文本连接在一起:

text = '\n'.join(element.text for element in soup.findAll('p', ...))

另外,我建议您升级到BeautifulSoup的最新版本。

find
仅查找第一个元素。您需要
findAll
,它将返回元素列表

您可以按如下方式将它们的文本连接在一起:

text = '\n'.join(element.text for element in soup.findAll('p', ...))

另外,我建议您升级到BeautifulSoup的最新版本。

谢谢,但我收到以下错误:回溯(最近一次调用):文件“”,第1行,在AttributeError中:“ResultSet”对象没有属性“text”,谢谢,但我收到以下错误:回溯(最近一次调用):文件“”,第1行,在AttributeError中:“ResultSet”对象没有属性“text”