【发布时间】:2023-03-13 02:56:01
【问题描述】:
我有一个 HTML sn-p,如下所示:
<div class="myTestCode">
<strong>Abc: </strong> test1</br>
<strong>Def: </strong> test2</br>
</div>
如何在 Beautiful Soup 中解析得到:
Abc: test1, Def: test2
这是我迄今为止尝试过的:
data = """<div class="myTestCode">
<strong>Abc: </strong> test1</br>
<strong>Def: </strong> test2</br>
</div>"""
temp = BeautifulSoup(data)
link = temp.select('.myTestCode')
#both didn't print the expected output as mentioned above
print str(link).split('<strong>')
print ''.join(link.stripped_strings)
【问题讨论】:
-
我也试过 str(link).split('') ''.join(link.stripped_strings) where link = temp.select('.myTestCode') 。 temp = BeautifulSoup(数据)
-
edit 你的帖子和你的代码。