https://segmentfault.com/q/1010000010845573

import re
#reg=r'\s+[^(href)]*=\"[^<>]+\"'
reg = r'\b(?!(?:href|src))\w+=(["\']).+?\1'
with open(r'input.txt','r',encoding='ISO-8859-15') as f_read:
html= f_read.read()
result = re.sub(reg,"",html)
#print(type(result))
result = result.replace('<table>','<table class="table14_3">')
#result = result.replace('<img>','<img src="min_images/new_logo.jpg">')
result = result.replace('<span>','').replace('</span>','')
print(result)
with open(r'output.txt','w',encoding='ISO-8859-15') as f_write:
f_write.write(result)

python 去掉html中其他属性,只保留href 和 src的更多相关文章

  1. Python: 去掉字符串中的非数字(或非字母)字符

    >>> crazystring = ‘dade142.;!0142f[.,]ad’ 只保留数字>>> filter(str.isdigit, crazystring ...

  2. Python 去掉文本中空行

    pandas 操作csv文件时,一直报错,排查后发现csv文本中存在很多“空行”: So 需要把空行全部去掉: def clearBlankLine(): file1 = open('text1.tx ...

  3. C#中如何只保留小数点后面两位?

    string.format("%.4f",1/3) 1.Math.Round(0.333333,2);//按照四舍五入的国际标准2. double dbdata=0.335333; ...

  4. python去掉字符串中空格的方法

    1.strip():把头和尾的空格去掉 2.lstrip():把左边的空格去掉 3.rstrip():把右边的空格去掉 4.replace('c1','c2'):把字符串里的c1替换成c2.故可以用r ...

  5. python去掉字符串中重复字符的方法

      If order does not matter, you can use   foo = "mppmt" "".join(set(foo)) set() ...

  6. C#去掉字符串两端空格以及去掉字符串中多余空格保留一个空格

    string str = " asdf asd saddf sdfwrqeqw a asdf "; string[] strs = str.Trim().Split(new cha ...

  7. python 删除字符串中的连续空格只保留一个

    目标是要去掉多余的空格字符,在相邻字符串中,只保留一个空格 紫梧桐 - 蛋壳公寓朝阳门店                                                 郑田力 可以利 ...

  8. 去掉html中的标签

    //去掉html中的图片 String regEx_image = "(<img.*src\\s*=\\s*(.*?)[^>]*?>)"; Pattern p_s ...

  9. 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从

    明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的 ...

随机推荐

  1. 《Windows核心编程系列》十二谈谈Windows内存体系结构

    Windows内存体系结构 理解Windows内存体系结构是每一个励志成为优秀的Windows程序员所必须的. 进程虚拟地址空间 每个进程都有自己的虚拟地址空间.对于32位操作系统来说,它的地址空间是 ...

  2. javascript 截取url参数

    var url="http://127.0.0.1:8080/photo/list.jsp?page=2&user=hongchen"; var params_arr = ...

  3. AJPFX关于File类复习

    file是一个路径,分为相对路径(eclipse)和绝对路径:1.构造方法有:File(String pathname ),File(String parent ,String child),File ...

  4. Fragment中获取Activity的Context (转)

    Fragment中获取Activity的Context时只需要this.getActivity()即可.     而不是许多人说的this.getActivity().getApplicationCo ...

  5. webstorm里直接调用命令行

    写代码写到一半要切换窗口出去敲命令行?webstorm的external tools可以帮你省下一点时间 举例说明,比如我要直接使用npm: ctrl+alt+s打开setting菜单,找到exter ...

  6. vs code 格式化 美化 html js css 插件 Beautify

    安装 Beautify 插件 然后 F1 输入 Beautify file 回车即可

  7. python练习2 购物车程序

    # -*- coding: utf-8 -*-# @Time : 2018/10/18 16:06# @Author : Two Brother# @EMAIL : yeluyide@163.com# ...

  8. h5编写帧动画

    var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame; var ...

  9. MFC中调用Windows API函数的方式

    windows aoi 函数的调用前面加::

  10. vue之package.json文件解析

    1.package.json是什么? 什么是Node.js的模块(Module)?在Node.js中,模块是一个库或框架,也是一个Node.js项目.Node.js项目遵循模块化的架构,当我们创建了一 ...