遇事不决,可问春风,春风不语,谨遵本心|

布都御魂

园龄:3年9个月粉丝:2关注:1

删除img标签里的width和height属性,并在img标签前后加一个br标签

                # 提取img标签
                tree_img = etree.HTML(content)
                width = tree_img.xpath('//img//@width')[0]
                height = tree_img.xpath('//img//@height')[0]
                # 替换掉width=,和height=
                content = content.replace('height=', '').replace('width=', '').replace('"' + width + '"', '').replace(
                    '"' + height + '"', '')
                # 改成<p><br\><img src="1.jpg"><br\></p>
                img_list = re.findall('<img(.*?)>', content)
                for img in img_list:
                    img_old = '<img' + img + '>'
                    img_new = '<br/>' + img_old + '<br/>'
                    content = content.replace(img_old, img_new)
                content=content.replace('<p>','<br/><br/><p>').replace('</p>','</p><br/><br/>')

 

本文作者:布都御魂

本文链接:https://www.cnblogs.com/wolvies/p/17552922.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   布都御魂  阅读(95)  评论(0编辑  收藏  举报
   
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起