lxml.html删除节点树和tag对
# encoding: utf-8
import StringIO
from apihelper import info, info_save
from lxml import etree, html
from lxml.html.clean import Cleaner
strhtml = '''\
<html>
<head>
<script type="text/javascript" src="evil-site"></script>
<link rel="alternate" type="text/rss" src="evil-rss">
<style>
body {background-image: url(javascript:do_evil)};
div {color: expression(evil)};
</style>
</head>
<body onload="evil_function()">
<!-- I am interpreted for EVIL! -->
<a href="javascript:evil_function()">a link</a>
<a href="#" onclick="evil_function()">another link</a>
<p onclick="evil_function()">a paragraph</p>
<div style="display: none">secret EVIL!</div>
<object> of EVIL! </object>
<iframe src="evil-site"></iframe>
<form action="evil-site">
Password: <input type="password" name="password">
</form>
<blink>annoying EVIL!</blink>
<a href="evil-site">spam spam SPAM!</a>
<image src="evil!">
<div id='nav' class='nav'>this is nav</div>
</body>
</html>'''
# strhtml = '''<html><head></head>
# <body><div>aaa</div></body>
# </html>'''
etree.DEBUG = 1
print etree.LIBXML_VERSION
utf8_parser=html.HTMLParser(encoding='utf8')
# f = open(xmlFile)
# xml = f.read()
# f.close()
doc=html.fromstring(strhtml, parser=utf8_parser)
# weather = doc.xpath('body/object')
# doc.find('.//body/object').drop_tag()
# doc.find('.//body/object').drop_tree()
doc.find('.//body').drop_tree()
# print '\r\n'.join(doc)
# print info_save(doc)
# print html.tostring(doc)
最新文章
- Moon.Orm 常见查询实例
- CSS学习笔记2-2d变换和过渡属性
- Mac 可设置环境变量的位置、查看和添加PATH环境变量
- 备份mysql
- Java中的大数处理类BigInteger和BigDecimar浅析
- hdu 3303 Harmony Forever (线段树 + 抽屉原理)
- QT5新手上路(1)安装
- JAVA8 HashMap 新特性
- Redis之(二)数据类型及存储结构
- .net如何引用该命名空间
- 在.net core web项目中生成二维码
- makefile笔记3 - makefile规则
- VS Code 安装 C++ 调试环境
- 三、xadmin----内置插件
- python 处理xml
- UVa 12186 工人的请愿书(树形DP)
- Python 3 与 Javascript escape 传输确保数据正确方法和中文乱码解决方案
- spark和hadoop比较
- iOS中响应者链条-触摸事件,hitTest方法坐标转换
- Mac下新安装的MySQL无法登陆root用户解决方法
热门文章
- 零基础学html第一天
- luogu2221 [HAOI2012]高速公路
- Lambda与LINQ
- Python 绘制棋盘
- eclipse里导入maven项目有红叉的解决办法
- CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]
- 八、ISP 接口隔离原则
- JDK从1.8.x升级到9.0.1后Tomcat 8.0.x不能启动
- hadoop2.5.2学习及实践笔记(三)—— HDFS概念及体系结构
- Ajax---概念介绍