我想从下面的样本HTML
中获得Orange
和1p
。
我可以得到像Orange1p
这样的集合句,但不能单独得到两个句子。
有办法得到两个句子吗?
样品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']