当前位置: 首页 > news >正文

引流用的电影网站怎么做wordpress浏览速度

引流用的电影网站怎么做,wordpress浏览速度,文字图片设计制作在线,网站后台模板论坛动手写的Python的HTML语法分析器#xff08;面向对象#xff09; 主要包括4个文件#xff0c;util.py文件主要负责截取每个块。 rules.py文件定义两个类#xff0c;超类Rule和分别对应的子类#xff0c;子类定义了不同的划分块的要求,子类包换action函数#xff0c;调用h… 动手写的Python的HTML语法分析器面向对象 主要包括4个文件util.py文件主要负责截取每个块。 rules.py文件定义两个类超类Rule和分别对应的子类子类定义了不同的划分块的要求,子类包换action函数调用handler处理 handlers.py定义了处理类超类定义了方法子类通过名字调用 markup.py定义了超类parser定义了子类basicTextParser,超类主要负责创造过滤器添加规则对每个块执行处理。 #handler.py# -*- coding: cp936 -*-class Handler: 处理从parser调用的方法对象 这个解析器会在每个块的开始部分调用start和end()方法使用合适的块名作为参数。sub()会用于 正则表达式替换中当使用了emphasis这样的名字调用时它会返回核实的替换函数def callback(self,prefix,name , *args): method getattr(self , prefix name , None)if callable(method):return method(*args)def start(self ,name): self.callback(start_,name)def end(self,name): self.callback(end_ ,name)def sub(self,name):def substitution(match): result self.callback(sub_, name,match)if result is None: result match.group(1)return resultreturn substitutionclass HTMLRenderer(Handler): 用于生成HTML的具体处理程序 类中所有的方法都可以通过超类处理程序的START、end()、sub()方法来访问他们实现了HTML的基本标签def start_document(self):print htmlheadtitle.../title/headbodydef end_document(self):print /body/htmldef start_paragraph(self):print pdef end_paragraph(self):print /pdef start_heading(self):print h2def end_heading(self):print h2def start_list(self):print uldef end_list(self):print /uldef start_listitem(self):print lidef end_listitem(self):print /lidef start_title(self):print h1def end_title(self):print /h1def sub_emphasis(self,match):return em%sem % match.group(1)def sub_url(self ,match):return a href%s%s/a % (match.group(1),match.group(1))def sub_mail(self,match):return a hrefmailto:%s%s/a % (match.group(1),match.group(1))def feed(self,data):print data # -*- coding: cp936 -*-#rules.pyclass Rule:所有规则的基类def action(self,block ,handler): handler.start(self.type) handler.feed(block) handler.end(self.type)return Trueclass HeadingRule(Rule): 标题占一行且标题的数目不大于70个字符且最后不能以冒号结尾 type headingdef condition(self,block):return not \n in block and len(block)70 and not block[-1]:class TitleRule(HeadingRule): 题目是文档的第一个块前提他是大标题 type title first Truedef condition(self,block):if not self.first:return False self.first Falsereturn HeadingRule.condition(self, block)class ListItemRule(Rule): type listitemdef condition(self,block):return block[0]-def action(self,block,handler): handler.start(self.type) handler.feed(block[1:].strip()) handler.end(self.type)return Trueclass ListRule(ListItemRule): type list inside Falsedef condition(self,block):return Truedef action(self,block,handler):if not self.inside and ListItemRule.condition(self, block): handler.start(self.type) self.insideTrueelif self.inside and not ListItemRule.condition(self, block): handler.end(self.type) self.insideFalsereturn Falseclass ParagraphRule(Rule): type paragraphdef condition(self,block):return True #util.pydef lines(file):for line in file:yield lineyield \ndef blocks(file): block []for line in lines(file):if line.strip(): block.append(line)elif block:yield .join(block).strip() block[]   #markup.pyimport sys , re from handlers import *from util import *from rules import *class Parser: the processer of this , read data ,then use rule , and control to process data block#initial def __init__(self,handler): self.handler handler self.rules [] self.filters []#addrule to the Parser def addRule(self,rule): self.rules.append(rule)#add filter to the Parser def addFilters(self,patten,name):def filter(block , handler):return re.sub(patten,handler.sub(name),block) self.filters.append(filter)def parse(self,file): self.handler.start(document)for block in blocks(file):for filter in self.filters: block filter(block , self.handler)for rule in self.rules:if rule.condition(block): last rule.action(block,self.handler)if last:break self.handler.end(document)class BasicTextParser(Parser):def __init__(self,hanler): Parser.__init__(self,handler) self.addRule(ListRule()) self.addRule(ListItemRule()) self.addRule(TitleRule()) self.addRule(HeadingRule()) self.addRule(ParagraphRule()) self.addFilters(r\*(.?)\*, emphasis) self.addFilters(r(http://[\.a-zA-z/]), url) self.addFilters(r([\.a-zA-Z/][\.a-zA-z][a-zA-Z]), mail)handler HTMLRenderer()parser BasicTextParser(handler)f open(rD://python27/input.txt)parser.parse(f) posted on 2012-03-06 15:47 lzhenf 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/lzhenf/archive/2012/03/06/2382056.html
http://www.pierceye.com/news/159210/

相关文章:

  • 云购物网站建设wordpress离线编辑
  • 有没有网站开发团队郑州网站制作电话
  • 网站怎么做登陆免费虚拟机
  • 中国移动网站备案管理系统不能用科普网站建设的支持力度
  • 谁教我做啊谁会做网站啊企业网站模板seo
  • 自己建立一个网站需要什么wordpress 平衡插件
  • 邯郸手机建站价格青海网站开发 建设
  • 苏州 手机网站免费个人简历模板电子版可填写
  • 永州内部网站建设公司wordpress 模版开发
  • 云建站优势门户网站如何建设方案
  • 网站建设收费标准不一湖州网站开发公司
  • asp制作网站青岛建网站公司
  • 人人商城程序做的网站打不开百度网盘客户端下载
  • 医疗器械注册证查询网站优化推广服务
  • 网站制作网页做简单的网站首页
  • 怎样做网站上的语种链接泰安网络犯罪案件
  • soap公司网站建设国家游戏网站
  • 网站可以用什么做安阳区号是什么
  • 网站建设实战李静如何建设网站的能力
  • 威海 网站开发做家具的网站有哪些
  • 宁波网站建设公司怎么报价网页打开速度慢的解决方法
  • 有趣的网站有哪些推荐关键词没有排名的网站怎么做
  • 昆山网站制作哪家强海淀区企业网络公司
  • 北京网站制建设公司永兴县网站建设服务商
  • 嘉兴做网站优化公司江阴网站优化公司
  • dz可以做旅游网站吗wordpress 4.1.1 漏洞
  • 谷歌网站地图生成福州便民网免费发布信息
  • 最新军事战争新闻超级优化大师
  • 好的网站建设公司排名网站建设 交易保障
  • 怎么查看网站外链效果代理注册公司有什么风险