2012年11月5日

jinja2.Markup 对HTML文本文件进行处理

摘要: classjinja2.Markup([string])Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped. This implements the__html__interface a couple of frameworks and web applications use.Markupis a direct subclass ofunicodeand provides all the methods ofunicodejust that it escapes 阅读全文

posted @ 2012-11-05 20:53 百年孤寂dwn 阅读(1224) 评论(0) 推荐(0) 编辑

python模块之HTMLParser: 解析html,获取url

摘要: HTMLParser是python用来解析html的模块。它可以分析出html里面的标签、数据等等,是一种处理html的简便途径。HTMLParser采用的是一种事件驱动的模式,当HTMLParser找到一个特定的标记时,它会去调用一个用户定义的函数,以此来通知程序处理。它主要的用户回调函数的命名都是以handler_开头的,都是HTMLParser的成员函数。当我们使用时,就从HTMLParser派生出新的类,然后重新定义这几个以handler_开头的函数即可。这几个函数包括:handle_startendtag 处理开始标签和结束标签handle_starttag 处理开始标签,比如< 阅读全文

posted @ 2012-11-05 20:51 百年孤寂dwn 阅读(779) 评论(0) 推荐(0) 编辑

导航