Python相当于PHP的strip_tags?
e-s*_*tis 38
Python标准库中没有这样的东西.这是因为Python是一种通用语言,而PHP最初是一种面向Web的语言.
不过,您有3个解决方案:
re.sub(r'<[^>]*?>', '', value)是一个快速而肮脏的解决方案.Joh*_*ooy 15
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(htmltext)
''.join([e for e in soup.recursiveChildGenerator() if isinstance(e,unicode)])
Run Code Online (Sandbox Code Playgroud)
小智 7
from bleach import clean
print clean("<strong>My Text</strong>", tags=[], strip=True, strip_comments=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11404 次 |
| 最近记录: |