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

python使用bs4模組 去除html標籤字串方法

使用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)