python 保留html标签,Python - 剥离html标签中的字符串,保留链接,但处于已更改的形式...

有没有办法从字符串中删除所有的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' 来代替

myA.animation

,但

demo

编辑: 现在它似乎工作:

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

是的,只有两种类型的链接。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值