所以前几天,SOCommunity 帮我做了一个解析器。即:
def MyList(self):
class _MyList(list):
def __init__(self, parent):
self.parent = parent
list.__init__(self)
top = current = _MyList(None)
ntab_old = 0
for line in self.raw_data:
ntab = line.count('\t')
if(ntab_old > ntab):
for _ in range(ntab_old-ntab):
current = current.parent
elif(ntab_old<ntab):
current.append(_MyList(current))
current = current[-1]
current.append(line.strip('\t').strip('|'))
ntab_old =ntab
return top
像这样解析数据:
|[nothing detected] www.neopets.com/
|status: (referer=http://www.google.com)saved 55189 bytes /fetch_d4cd213a56276ca726ddd437a1e75f1024ab7799
|file: fetch_d4cd213a56276ca726ddd437a1e75f1024ab7799: 55189 bytes
|file: decoding_367af53b4963986ecdeb9c09ce1a405b5b1ecd91: 68 bytes
|[nothing detected] (script) images.neopets.com/js/common.js?v=6
|status: (referer=http://www.google.com)saved 1523 bytes /fetch_8eeadcc08d4cb48c02dedf18648510b75190d1d7failure: [Errno 13] Permission denied: '/tmp/tmpsha1_8d7fb3ff1ef087c7ea2bf044dee294735a76ed4b.js'
|file: fetch_8eeadcc08d4cb48c02dedf18648510b75190d1d7: 1523 bytes
这应该返回包含每个子部分的嵌套列表。但是,不知从何而来,我收到了这些错误:
current.append(line.strip('\t').strip('|'))
AttributeError: 'NoneType' object has no attribute 'append'
任何帮助,将不胜感激