[英]Python 3 Beautifulsoup: Get span tag value with specific text which is also randomly placed within the html tree
[英]How to get every sentence enclose by tag in beautifulsoup( Not only text but also html tags etc / Python)
我想从下面的示例HTML
获取Orange
和1p
。
我可以得到像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.