最好的选择是
extract()换行。它比您想象的要容易:)。
>>> from bs4 import BeautifulSoup as BS>>> html = """<div>... some text <br>... <span> some more text </span> <br>... <span> and more text </span>... </div>""">>> soup = BS(html)>>> for linebreak in soup.find_all('br'):... linebreak.extract()... <br/><br/>>>> print soup.prettify()<html> <body> <div> some text <span> some more text </span> <span> and more text </span> </div> </body></html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)