function doGet() { const datos = obtenerVentasLocales(); // Devolvemos un JSON estructurado con los encabezados correctos para permitir CORS return ContentService.createTextOutput(JSON.stringify(datos)) .setMimeType(ContentService.MimeType.JSON); } function obtenerVentasLocales() { const locales = [ { id: 'CC', url: 'http://net.fh.cl:88/reporte_ventas.asp' }, { id: 'CN', url: 'http://net.fh.cl:85/reporte_ventas.asp' }, { id: 'RE', url: 'http://net.fh.cl:92/reporte_ventas.asp' }, { id: 'MT', url: 'http://net.fh.cl:82/reporte_ventas.asp' }, { id: 'LL', url: 'http://net.fh.cl:81/reporte_ventas.asp' }, { id: 'QT', url: 'http://net.fh.cl:84/reporte_ventas.asp' }, { id: 'PU', url: 'http://net.fh.cl:83/reporte_ventas.asp' } ]; let resultados = []; locales.forEach(local => { try { const response = UrlFetchApp.fetch(local.url, { muteHttpExceptions: true, deadline: 15 }); const html = response.getContentText('ISO-8859-1'); const regex = /]*bgcolor=["']?D7FFFF["']?[^>]*>.*?<\/b>\s*=\s*\s*\$ ([\d\.]+)\s*<\/b><\/td>/i; const match = html.match(regex); if (match && match[1]) { const valorLimpio = match[1].replace(/\./g, ''); resultados.push({ id: local.id, status: 'OK', valor: parseInt(valorLimpio, 10), texto: match[1] }); } else { resultados.push({ id: local.id, status: 'E_PARSE', valor: 0, texto: 'Línea no encontrada' }); } } catch (e) { resultados.push({ id: local.id, status: 'E_CONN', valor: 0, texto: 'Error de Conexión o Timeout' }); } }); return resultados; }