简单的生成html,简单生成html,[Python]代码cl
简单的生成html,简单生成html,[Python]代码cl
[Python]代码
class Tag: def __init__(self,tag,**attrs): self.attrs = {} self.childs= [] self.tag = tag.lower() if attrs: self.attr(**attrs) def __str__(self): s = '<'+self.tag; for a in self.attrs: s += ' '+a+'=\''+str(self.attrs[a])+'\'' s += '>\n' for c in self.childs: s += str(c) s +='</'+self.tag+'>\n' return s def __next__(self): for c in self.childs: yield c def attr(self,**attrs): for a in attrs: self.attrs[a] = attrs[a] return self def innerhtml(self,*childs): self.childs = [] self.childs += childs return self def append(self,*childs): self.childs += childs return self def __iter__(self): return iter(self.childs)if __name__ =='__main__': html = Tag('html').innerhtml( Tag('head'),\ Tag('body').innerhtml(Tag('a',onmouseover='alert("hello")',href='#',onclick='alert("hello")')\ .innerhtml('hello world'))) print(html)
相关内容
- Levenshtein字符串相似度,Levenshtein字符串,Levenshtein距
- 抓取网上的小说章节并写入txt文件,抓取网上章节txt
- 批量删除所下载的.git文件夹,批量删除.git文件夹,批量
- 得到N以内的所有的质数,得到N质数,getPrime.pyi
- peewee的简单封装,peewee简单封装,[Python]代码im
- python 生成IP段,python生成ip,[Python]代码#!
- Python 扫描IP段 指定端口是否开放,pythonip,TCP21.py#!/u
- 使用python Tk的实现tablepanel+treeview,pythontablepanel,window
- python BeautifulSoup 抓取网页内指定内容,,# _*_ coding
- 获得本机硬件信息,获得机硬件信息,注意:这段代码需
评论关闭