有没有办法从字符串中删除所有的html标签,但留下一些链接并更改它们的表示形式?例如:Python - 剥离html标签中的字符串,保留链接,但处于已更改的形式
description:
Animation params. For other animations, see myA.animation and the animation parameter under the API methods. The following properties are supported:
-
duration
- The duration of the animation in milliseconds. easing
-
A string reference to an easing function set on the
Math
object. See demo.
,我想只有 'myA.animation' 来代替
,但
编辑: 现在它似乎工作:
def cleanComment(comment):
soup = BeautifulSoup(comment, 'html.parser')
for m in soup.find_all('a'):
if str(m) in comment:
if not m['href'].startswith("#"):
comment = comment.replace(str(m), m['href'] + " : " + m.__dict__['next_element'])
soup = BeautifulSoup(comment, 'html.parser')
comment = soup.get_text()
return comment
2017-02-23
Ratka
+0
你的例子是全球规则为你html?或者它可能是你想要保存的一些链接,但其他链接不是? –
+0
是的,只有两种类型的链接。 –