繁体   English   中英

如何让每个句子都用beautifulsoup中的标签括起来(不仅是文本,还有html标签等/Python)

[英]How to get every sentence enclose by tag in beautifulsoup( Not only text but also html tags etc / Python)

我想从下面的示例HTML获取Orange1p

我可以得到像Orange1p这样的聚集语句,但不能单独得到 2 个语句。

有什么办法可以得到2句话?

示例HTML

<td class="info">Orange<br/>1p</td>

当前使用的代码:

soup = BeautifulSoup(html_doc, 'html.parser')
data = soup.find("td", {"class": "info"}) # with current output of `Orange1p`
from bs4 import BeautifulSoup

html_doc = """<td class="info">Orange<br/>1p</td>"""

soup = BeautifulSoup(html_doc, 'html.parser')

print(list(soup.find("td", {'class': 'info'}).strings))

输出:

['Orange', '1p']

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM