lum*_*ere 18 python beautifulsoup html-parsing
我在python中使用BeautifulSoup解析html
我不知道如何在提取文本元素时插入空格
这是代码:
import BeautifulSoup
soup=BeautifulSoup.BeautifulSoup('<html>this<b>is</b>example</html>')
print soup.text
Run Code Online (Sandbox Code Playgroud)
那么输出就是
thisisexample
但我想为此插入一个空格
是例子
我该如何插入空格?
mou*_*uad 40
getText改为使用:
import BeautifulSoup
soup=BeautifulSoup.BeautifulSoup('<html>this<b>is</b>example</html>')
print soup.getText(separator=u' ')
# u'this is example'
Run Code Online (Sandbox Code Playgroud)