# 提取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/>')
标签:img,标签,replace,content,width,height From: https://www.cnblogs.com/wolvies/p/17552922.html