我很難試圖擺脫從某個網頁上抓取的文本中所有額外的HTML標籤,但是,Python中的str.replace()
似乎不適用於像<br>
和=
這樣的目標,而其他標籤,如<li></li>
將被成功替換。如何在Python中str.replace()<br>或'='?
這是我的代碼。
str(txt).replace('<li>', '')
.replace('</li>', '')
.replace('<ol>', '')
.replace('</ol>', '')
.replace('<br>', '')
.replace('=', '')
任何意見將不勝感激。
可能的複製(http://stackoverflow.com/questions/753052/strip-html-from -strings-in-python) –