Html 使用BeautifulSoup,我可以在标签之间获得其他字符串的文本,以便在这些字符串之间分离吗?

Html 使用BeautifulSoup,我可以在标签之间获得其他字符串的文本,以便在这些字符串之间分离吗?,html,python-3.x,beautifulsoup,Html,Python 3.x,Beautifulsoup,所以,我一直在用BeautifulSoup爬行,但我遇到了一些混乱的html标记 这是一个例子: <html> <body> <p>Hey</p> <div> <div> <span class="date">0817</span> </div>

所以,我一直在用BeautifulSoup爬行,但我遇到了一些混乱的html标记

这是一个例子:

<html>
    <body>
        <p>Hey</p>
        <div>
            <div>
                <span class="date">0817</span>
            </div>
        </div>
        <p>I want all of those</p>
        <div>
            <div>
                <p>But I want to get those separately</p>
            <div>
        </div>
        <p>Hope this work</p>
    </body>
</html>
我可能会得到这个:

"Hey0817I want all of thoseBut I want to get those separatelyHope this work"
问题是,我能得到那些带有字符串作为分隔符的文本吗?分隔符,用于在其他标记之间分隔内容,例如:

"@@@Hey@@@0817@@@Iwant all of those@@@But I want to get those separately@@@Hope this work"
or
"Hey@@@0817@@@Iwant all of those@@@But I want to get those separately@@@Hope this work@@@"
or
"Hey@@@0817@@@Iwant all of those@@@But I want to get those separately@@@Hope this work"
这样我以后就可以用其他代码通过“@@@”来解析这些文本了? 或者有没有类似的散步活动? 任何建议都会大有帮助。感谢您的关注和时间!
希望你能启发我。

我将使用
。获取文本

soup.body.get_text('@@@')
一条带子会更好:

soup.body.get_text('@@@').strip()
您也可以展开换行符:

print(soup.body.get_text('@@@').strip())

我将使用
。获取文本

soup.body.get_text('@@@')
一条带子会更好:

soup.body.get_text('@@@').strip()
您也可以展开换行符:

print(soup.body.get_text('@@@').strip())

如果需要列表,可以使用:

item_text=[t.text代表正文中的t.find_all()]

如果您确实需要分隔符:


body.get_text('@@')
如果需要列表,可以使用:

item_text=[t.text代表正文中的t.find_all()]

如果您确实需要分隔符:


body.get_text('@@')

您是否尝试过
body.get_text('@@')
?不知道get_text有这个选项!谢谢你,路易!您是否尝试过
body.get_text('@@')
?不知道get_text有这个选项!谢谢你,路易!谢谢你花时间在这上面。这真的很有帮助!祝你有美好的一天!谢谢你花时间在这上面。这真的很有帮助!祝你有美好的一天!