如何使用uls标签提取完整的段落

2024-10-03 06:24:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从下面的html代码中提取除了<p><a href><rel>等之外的完整文本。在

<p>Many of the features that made the Samsung Galaxy S4 one of the most anticipated phones in recent history -- such as its 5-inch 1920 x 1080 <a href="http://www.bubblews.com/news/421662-samsung-galaxy-s4-worlds-first-full-hd-super-amoled-display" rel="nofollow" target="_blank">Full HD Super AMOLED display</a>, its powerful processors (<a href="http://www.samsung.com/global/business/semiconductor/minisite/Exynos/blog_Spotlight_on_the_Exynos5Octa.html" rel="nofollow" target="_blank">Samsung Exynos 5 Octa</a> in the international version and <a href="http://www.qualcomm.com/snapdragon/blog/topics/snapdragon 600" rel="nofollow" target="_blank">Qualcomm Snapdragon 600</a> in the U.S. version) and 16GB, 32GB and 64GB storage options -- are now bringing grief to those who rushed to purchase the fourth-generation Galaxy S series smartphone upon its late April release.</p>

我试过下面的代码

^{pr2}$

但是给出了以下输出

三星Galaxy S4的许多功能使其成为近期史上最受期待的手机之一,比如它的5英寸1920x1080

我无法得到完整的文本,它应该给出文本后的href和rel等标签,请建议我如何得到下面的输出。在

三星Galaxy S4是近年来最受期待的手机之一,其5英寸1920 x 1080全高清超级AMOLED显示了其强大的处理器。国际版的三星Exynos 5 Octa和美国版的高通Snapdragon 600)以及16GB、32GB和64GB存储选项现在给那些在4月底发布的第四代Galaxy S系列智能手机的人带来了悲伤。在

谢谢。。在


Tags: thein文本comhttptargetwwwgalaxy
1条回答
网友
1楼 · 发布于 2024-10-03 06:24:56

您可以使用.text

>>> from bs4 import BeautifulSoup
>>> html = '<p>Many of the features that made the Samsung Galaxy S4 one of the most anticipated phones in recent history   such as its 5-inch 1920 x 1080 <a href="http://www.bubblews.com/news/421662-samsung-galaxy-s4-worlds-first-full-hd-super-amoled-display" rel="nofollow" target="_blank">Full HD Super AMOLED display</a>, its powerful processors (<a href="http://www.samsung.com/global/business/semiconductor/minisite/Exynos/blog_Spotlight_on_the_Exynos5Octa.html" rel="nofollow" target="_blank">Samsung Exynos 5 Octa</a> in the international version and <a href="http://www.qualcomm.com/snapdragon/blog/topics/snapdragon 600" rel="nofollow" target="_blank">Qualcomm Snapdragon 600</a> in the U.S. version) and 16GB, 32GB and 64GB storage options   are now bringing grief to those who rushed to purchase the fourth-generation Galaxy S series smartphone upon its late April release.</p>'
>>> soup = BeautifulSoup(html)
>>> print soup.p.text
Many of the features that made the Samsung Galaxy S4 one of the most anticipated phones in recent history   such as its 5-inch 1920 x 1080 Full HD Super AMOLED display, its powerful processors (Samsung Exynos 5 Octa in the international version and Qualcomm Snapdragon 600 in the U.S. version) and 16GB, 32GB and 64GB storage options   are now bringing grief to those who rushed to purchase the fourth-generation Galaxy S series smartphone upon its late April release.

相关问题 更多 >