import datetime
n = 0
for i in range(0, len(table0.rows) + 1, 3):
date = table0.cell(i, 1).text
# 有的条目时间是空的,这里不做过多判别
if '/' in date:
date = datetime.datetime.strptime(date, '%d/%m').strftime('2020-%m-%d')
else:
date = '-'
title = table0.cell(i + 1, 1).text.strip()
dfn = tables[j].cell(i, 3).text.strip()
print(n, date, tite, dfn)
n = 0
for j in range(len(tables)):
for i in range(0, len(tables[j].rows)+1, 3):
date = tables[j].cell(i, 1).text
if '/' in date:
date = datetime.datetime.strptime(date, '%d/%m').strftime('2020-%m-%d')
else:
date = '-'
title = tables[j].cell(i + 1, 1).text.strip()
dfn = tables[j].cell(i, 3).text.strip()
n += 1
print(n, date, title, dfn)
except Exception as error:
# 捕获异常,也可以用log写到日志里方便查看和管理
print(error)
continue