"""找出CATD中被损坏的记录（最后一个元素为空的行）"""
import re
html = open('index_main.html', encoding='utf-8').read()
m = re.search(r'(const\s+)?CATD\s*=\s*\[', html)
start = m.end() - 1
depth = 0
i = start
while i < len(html):
    c = html[i]
    if c == '[':
        depth += 1
    elif c == ']':
        depth -= 1
        if depth == 0:
            end = i + 1
            break
    i += 1
catd_block = html[start:end]

# 找损坏行：以 ", ]" 或 ",]" 结尾的子数组
# 正常行: [..., "details/xxx.html"],
# 损坏行: [..., ],  或 [...,],
broken = re.findall(r'\[[^\[\]]*?,[\s]*\],?', catd_block)
print('疑似损坏行数量:', len(broken))
for b in broken[:15]:
    print('  ', b)
