lxml应用例子,lxml例子,#!pythonimpo
文章由Byrx.net分享于2019-03-23 08:03:10
lxml应用例子,lxml例子,#!pythonimpo
#!pythonimport lxml.htmlimport codecs, locale, syssys.stdout = codecs.getwriter(locale.getdefaultlocale()[1])(sys.stdout, 'replace')def process_row(row): for cell in row.xpath('./td'): inner_tables=cell.xpath('./table') if len(inner_tables)<1: yield cell.text_content() else: yield [process_table(t) for t in inner_tables]def process_table(table): return [process_row(row) for row in table.xpath('./tr')]html= lxml.html.parse("11078.htm")tab=html.xpath("//*[contains(@class,'productlist')]")[0]# Output to terminalfor row in tab.xpath('./tr'): k=[] for cell in row.xpath('./td[3]|td[4]/a[1]'): #inner_tables=cell.xpath('./table') #if len(inner_tables)<1: for sib in cell.itertext(): k.append('"'+sib.strip()+'"') print ','.join(k)#该片段来自于http://byrx.net
相关内容
- 用pydev开发python,pydev开发python,[Python]代码co
- python windows平台锁定键盘,python锁定,阻断windows平台下
- Python 分割TXT文件成4K的TXT文件,python4k,[Python]代码#
- Python 最近最少使用算法,Python使用算法,[Python]代码#
- Python 最长公共子串算法,python串算法,[Python]代码#!
- Python 实现enum的功能,python实现enum,[Python]代码cl
- Python viterbi算法,pythonviterbi算法,[Python]代码de
- python 中文分词——FMM算法,,[Python]代码im
- Python 设置检查点简单实现,python检查,[Python]代码#
- Python 126邮箱自动登录程序,python126,[Python]代码im
评论关闭