嗨,我目前正在寻找一种用空格替换代码中标签的方法。
soup = BeautifulSoup("<p>Something</p><p>Something</p>")
print soup.get_text()
SomethingSomething
#When I do get_text now I would get SomethingSomething but I want Something Something
该get_text
函数允许您指定分隔各个元素的文本的内容:
In [1]: from bs4 import BeautifulSoup
In [2]: soup = BeautifulSoup("<p>Something</p><p>Something</p>")
In [3]: print soup.get_text(separator=u' ')
Something Something
推荐人:http ://www.crummy.com/software/BeautifulSoup/bs4/doc/#get-text
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句