import re

with open(r'D:\Evolução categorias\dashboard_categorias.html', encoding='utf-8') as f:
    html = f.read()

scripts = re.findall(r'<script[^>]*>([\s\S]*?)</script>', html)
s = scripts[-1]

# Walk through tracking paren balance
depth = 0
for i, ch in enumerate(s):
    if ch == '(':
        depth += 1
    elif ch == ')':
        depth -= 1
        if depth < 0:
            print(f'EXTRA ) at pos {i}')
            print('Context:', repr(s[max(0,i-100):i+100]))
            depth = 0  # reset to continue finding more
