#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup

BASE = 'https://sistema.skeenmx.app'
USERNAME = 'JoseSkeen'
PASSWORD = 'SKr#902_88'

session = requests.Session()
r = session.get(f'{BASE}/login', timeout=30)
soup = BeautifulSoup(r.text, 'html.parser')
token = soup.find('input', {'name': '_token'})
token = token['value'] if token else ''

r = session.post(f'{BASE}/login', data={
    '_token': token,
    'username': USERNAME,
    'password': PASSWORD,
}, timeout=30, allow_redirects=True)

r = session.get(f'{BASE}/expediente/ver/1', timeout=30)
soup = BeautifulSoup(r.text, 'html.parser')

# Extraer tablas con th/td
for table in soup.find_all('table'):
    for tr in table.find_all('tr'):
        ths = tr.find_all('th')
        tds = tr.find_all('td')
        if ths and tds and len(ths) == len(tds):
            for th, td in zip(ths, tds):
                key = ' '.join(th.get_text(strip=True).split())
                val = ' '.join(td.get_text(strip=True).split())
                if key and val:
                    print(f'{key}: {val}')
    print('--- FIN TABLA ---')

# Buscar inputs/checkboxes
for inp in soup.find_all(['input', 'textarea', 'select']):
    name = inp.get('name') or inp.get('id') or ''
    val = inp.get('value') or ''
    checked = inp.get('checked')
    if name:
        print(f'INPUT {name}: value={val} checked={checked}')
