1. 程式人生 > >python使用bs4模塊 去除html標簽字符串方法

python使用bs4模塊 去除html標簽字符串方法

beautiful token div tro code rom 字符 ken pre

使用bs4模塊 去除html標簽方法

from bs4 import BeautifulSoup

s = ‘‘‘ 
/usr/sbin/tgt-admin <span class="token comment">#配置工具</span>
/usr/sbin/tgtadm  <span class="token comment">#管理target工具</span>
/usr/sbin/tgtd  <span class="token comment">#服務進程程序</span>
/usr/sbin/tgtimg <span class="token comment">#共享的映射文件設備工具</span></code></pre><div class="toolbar"></div></div>
‘‘‘‘
b = BeautifulSoup(s,"html.parser") #html.parser 是一個固定的值,是一個解析器

print(b.text)

python使用bs4模塊 去除html標簽字符串方法