# 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)

最新文章

  1. Moon.Orm 常见查询实例
  2. CSS学习笔记2-2d变换和过渡属性
  3. Mac 可设置环境变量的位置、查看和添加PATH环境变量
  4. 备份mysql
  5. Java中的大数处理类BigInteger和BigDecimar浅析
  6. hdu 3303 Harmony Forever (线段树 + 抽屉原理)
  7. QT5新手上路(1)安装
  8. JAVA8 HashMap 新特性
  9. Redis之(二)数据类型及存储结构
  10. .net如何引用该命名空间
  11. 在.net core web项目中生成二维码
  12. makefile笔记3 - makefile规则
  13. VS Code 安装 C++ 调试环境
  14. 三、xadmin----内置插件
  15. python 处理xml
  16. UVa 12186 工人的请愿书(树形DP)
  17. Python 3 与 Javascript escape 传输确保数据正确方法和中文乱码解决方案
  18. spark和hadoop比较
  19. iOS中响应者链条-触摸事件,hitTest方法坐标转换
  20. Mac下新安装的MySQL无法登陆root用户解决方法

热门文章

  1. 零基础学html第一天
  2. luogu2221 [HAOI2012]高速公路
  3. Lambda与LINQ
  4. Python 绘制棋盘
  5. eclipse里导入maven项目有红叉的解决办法
  6. CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]
  7. 八、ISP 接口隔离原则
  8. JDK从1.8.x升级到9.0.1后Tomcat 8.0.x不能启动
  9. hadoop2.5.2学习及实践笔记(三)—— HDFS概念及体系结构
  10. Ajax---概念介绍