参考前面的
Topic sourcedef start_element(self, name, attrs):
if name == 'pubDate':
self.db['dd'] = self.db['chda']
print(self.db['dd'])
def char_data(self, text):
self.db['chda'] = text
在start判断得不到想要的data字段
def end_element(self, name):
print('sax:end_element:%s' % name)
if name == 'pubDate':
self.db['ddddd'] = self.db['chda']
days = re.search(r'[\d]{2}',self.db['ddddd'])
print(days.group())
def char_data(self, text):
self.db['chda'] = text
在end判断就能得到想要的data字段 不知道我这样理解对不对: 读取是先读到start段的内容,然后再读到data,最后是end。 在start段判断的时候,data的数据还是上一行的数据,所以得到的不是自己想要的;而在end判断,当前行的data已经读取到了,所以得到的正是自己想要的。
- 1
迷迷的蛋
执行结果