FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Capturar pagina html y recuperar resultado
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Capturar pagina html y recuperar resultado
Posted: Thu Aug 22, 2024 10:35 PM
Hola buenas tardes para todos, no se si esto se pueda hacer con FW y la nueva clase WebView2 o con otra.

Necesitamos recuperar la informaci贸n de una pagina, luego de ingresar un dato en un get (input), hacer clic (debe ser desatendido) en un bot贸n para hacer otra consulta y luego si recuperar el resultado en html, para ser almacenado en variables del lado de FW.

Paso 1 - Ingresar a la p谩gina
https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces
Paso 2 - Completar el dato con el numero de identificaci贸n
Paso 3 - Hacer clic en el bot贸n "Buscar"



Paso 4 - Guardar en variables el contenido de las etiquetas con el resultado.



De antemano gracias :D

De antemano gracias
Saludos
LEANDRO AREVALO
Bogot谩 (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Fri Aug 23, 2024 05:41 AM

Estimado Leandro,

Se puede hacer con webview inyectando c贸digo javascript

Voy a probar a hacerlo y te comento

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Fri Aug 23, 2024 09:52 AM
1. Le pido a Claude ayuda. Le he pasado tu pregunta y le sugiero inyectar codigo javascript desde webview y me reponde lo siguiente:

Entiendo que necesitas automatizar un proceso de consulta en una p谩gina web de la DIAN (Direcci贸n de Impuestos y Aduanas Nacionales de Colombia) utilizando un WebView. Vamos a desglosar el proceso y crear un script que pueda realizar estas acciones de forma desatendida.

Para lograr esto, podemos usar JavaScript para interactuar con la p谩gina web dentro del WebView. Aqu铆 te presento una soluci贸n paso a paso:

Para implementar esta soluci贸n en tu aplicaci贸n con WebView, necesitar谩s seguir estos pasos:

1. Configura un WebView en tu aplicaci贸n

2. Carga la URL de la DIAN en el WebView:

https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces

3. Una vez que la p谩gina est茅 cargada, inyecta y ejecuta el script JavaScript proporcionado.

4. Desde el c贸digo nativo de tu aplicaci贸n, llama a la funci贸n realizarConsultaDIAN pasando el n煤mero de identificaci贸n como argumento.

4. Implementa un m茅todo en tu c贸digo nativo para recibir el resultado del WebView

Y propone este c贸digo:
Code (fw): Select all Collapse
// Funci贸n para realizar la consulta
function realizarConsultaDIAN(numeroIdentificacion) {
聽 聽 // Esperar a que la p谩gina se cargue completamente
聽 聽 document.addEventListener('DOMContentLoaded', function() {
聽 聽 聽 聽 // Paso 2: Completar el dato con el n煤mero de identificaci贸n
聽 聽 聽 聽 var inputNIT = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit');
聽 聽 聽 聽 if (inputNIT) {
聽 聽 聽 聽 聽 聽 inputNIT.value = numeroIdentificacion;
聽 聽 聽 聽 } else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el campo de entrada para el NIT');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 }

聽 聽 聽 聽 // Paso 3: Hacer clic en el bot贸n "Buscar"
聽 聽 聽 聽 var botonBuscar = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:btnBuscar');
聽 聽 聽 聽 if (botonBuscar) {
聽 聽 聽 聽 聽 聽 botonBuscar.click();
聽 聽 聽 聽 } else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el bot贸n de b煤squeda');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 }

聽 聽 聽 聽 // Esperar a que se carguen los resultados
聽 聽 聽 聽 setTimeout(function() {
聽 聽 聽 聽 聽 聽 // Recuperar el resultado en HTML
聽 聽 聽 聽 聽 聽 var resultadoHTML = document.querySelector('.resultado').innerHTML;
聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 // Aqu铆 puedes procesar el resultadoHTML como necesites
聽 聽 聽 聽 聽 聽 console.log('Resultado obtenido:', resultadoHTML);
聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 // Enviar el resultado al c贸digo nativo (depende de tu implementaci贸n espec铆fica)
聽 聽 聽 聽 聽 聽 if (window.Android) {
聽 聽 聽 聽 聽 聽 聽 聽 // Para Android
聽 聽 聽 聽 聽 聽 聽 聽 window.Android.recibirResultado(resultadoHTML);
聽 聽 聽 聽 聽 聽 } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.recibirResultado) {
聽 聽 聽 聽 聽 聽 聽 聽 // Para iOS
聽 聽 聽 聽 聽 聽 聽 聽 window.webkit.messageHandlers.recibirResultado.postMessage(resultadoHTML);
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 }, 2000); // Ajusta este tiempo seg煤n sea necesario
聽 聽 });
}

// Llamada a la funci贸n (esto se har铆a desde el c贸digo nativo)
// realizarConsultaDIAN('123456789');
El asume que vamos a usar Android 贸 iOS, pero lo vamos a adaptar para usar FWH. Continuamos...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Fri Aug 23, 2024 01:09 PM
Primer intento. Falta recoger los datos mostrados:
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWnd

聽 聽DEFINE WINDOW oWnd TITLE "Usando DIAN desde un webview" SIZE 1050, 700
聽 聽 
聽 聽oWebView = TWebView2():New( oWnd )

聽 聽oWebView:Navigate( "https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces" )
聽 聽// SysWait( 3 )
聽 聽oWebView:InjectJavascript( JavaScript() )
聽 聽// oWebView:OpenDevToolsWindow()
聽 聽oWebView:Eval( "consultaDIAN( '79760202' )" )

聽 聽ACTIVATE WINDOW oWnd CENTER ;
聽 聽 聽 ON RESIZE oWebView:SetSize( nWidth, nHeight )

聽 聽oWebView:End()

return nil

function Javascript()

聽 聽local cCode 

聽 聽TEXT INTO cCode 
聽 聽 聽 function consultaDIAN( numeroIdentificacion ) 
聽 聽 聽 {
聽 聽 聽 聽 聽var inputNIT = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit');
聽 聽 聽 聽 聽if (inputNIT) {
聽 聽 聽 聽 聽 聽 inputNIT.value = numeroIdentificacion;
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el campo de entrada para el NIT');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽} 聽 聽 
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽var botonBuscar = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:btnBuscar');
聽 聽 聽 聽 聽if (botonBuscar) {
聽 聽 聽 聽 聽 聽 botonBuscar.click();
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el bot贸n de b煤squeda');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽}
聽 聽 聽 }
聽 聽ENDTEXT

return cCode
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Fri Aug 23, 2024 06:36 PM
Antonio buenas tardes como estas?

Intentamos compilar el c贸digo que nos enviaste, pero no esta devolviendo este error. Lo estamos compilando con la versi贸n FWH2404 - xHarbour 1.3.1 Intl. (SimpLex) (Build 20240108) - BCC770
Code (fw): Select all Collapse
Application
===========
聽 聽Path and name: C:\fwh2404\samples\leandro.exe (32 bits)
聽 聽Size: 3,763,712 bytes
聽 聽Compiler version: xHarbour 1.3.1 Intl. (SimpLex) (Build 20240108)
聽 聽FiveWin 聽version: FWH 24.04
聽 聽C compiler version: Borland/Embarcadero C++ 7.7 (32-bit)
聽 聽Windows 8 64 Bits, version: 6.2, Build 9200 

聽 聽Time from start: 0 hours 0 mins 0 secs 
聽 聽Error occurred at: 08/23/24, 13:31:13
聽 聽Error description: Warning BASE/1004 聽Message not found: TWEBVIEW2:INJECTJAVASCRIPT

Stack Calls
===========
聽 聽Called from: source\rtl\tobject.prg => TWEBVIEW2:ERROR( 0 )
聽 聽Called from: source\rtl\tobject.prg => TWEBVIEW2:MSGNOTFOUND( 0 )
聽 聽Called from: source\rtl\tobject.prg => TWEBVIEW2:INJECTJAVASCRIPT( 0 )
聽 聽Called from: leandro.prg => MAIN( 15 )

System
======
聽 聽CPU type: 12th Gen Intel(R) Core(TM) i7-12700 2112 Mhz
聽 聽Hardware memory: 32510 megs

聽 聽Free System resources: 90 %
聽 聽 聽 聽 GDI 聽 聽resources: 90 %
聽 聽 聽 聽 User 聽 resources: 90 %

聽 聽Windows total applications running: 1
聽 聽 聽 1 , 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 

Variables in use
================
聽 聽Procedure 聽 聽 Type 聽 Value
聽 聽==========================
聽 聽TWEBVIEW2:ERROR
聽 聽 聽Param 聽 1: 聽 聽C 聽 聽"Message not found"
聽 聽 聽Param 聽 2: 聽 聽C 聽 聽"TWEBVIEW2"
聽 聽 聽Param 聽 3: 聽 聽C 聽 聽"INJECTJAVASCRIPT"
聽 聽 聽Param 聽 4: 聽 聽N 聽 聽1004
聽 聽 聽Local 聽 1: 聽 聽U 聽 聽
聽 聽 聽Local 聽 2: 聽 聽O 聽 聽Class: TWEBVIEW2
聽 聽 聽Local 聽 3: 聽 聽N 聽 聽13
聽 聽TWEBVIEW2:MSGNOTFOUND
聽 聽 聽Param 聽 1: 聽 聽C 聽 聽"INJECTJAVASCRIPT"
聽 聽 聽Param 聽 2: 聽 聽O 聽 聽Class: TWEBVIEW2
聽 聽TWEBVIEW2:INJECTJAVASCRIPT
聽 聽 聽Param 聽 1: 聽 聽C 聽 聽" 聽 聽 聽function consultaDIAN( numeroIdentificacion ) 聽 聽 聽{ 聽 聽 聽 聽 var inputNIT = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit'); 聽 聽 聽 聽 if (inputNIT) { 聽 聽 聽 聽 聽 聽inputNIT.value = numeroIdentificacion; 聽 聽 聽 聽 } else { 聽 聽 聽 聽 聽 聽console.error('No se encontr贸 el campo de entrada para el NIT'); 聽 聽 聽 聽 聽 聽return; 聽 聽 聽 聽 } 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽var botonBuscar = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:btnBuscar'); 聽 聽 聽 聽 if (botonBuscar) { 聽 聽 聽 聽 聽 聽botonBuscar.click(); 聽 聽 聽 聽 } else { 聽 聽 聽 聽 聽 聽console.error('No se encontr贸 el bot贸n de b煤squeda'); 聽 聽 聽 聽 聽 聽return; 聽 聽 聽 聽 } 聽 聽 聽}"
聽 聽MAIN
聽 聽 聽Local 聽 1: 聽 聽O 聽 聽Class: TWINDOW

Linked RDDs
===========
聽 聽DBF
聽 聽DBFFPT
聽 聽DBFBLOB
聽 聽DBFNTX

DataBases in use
================

Classes in use:
===============
聽 聽 聽1 ERROR
聽 聽 聽2 HASHENTRY
聽 聽 聽3 HBCLASS
聽 聽 聽4 HBOBJECT
聽 聽 聽5 TWINDOW
聽 聽 聽6 TBRUSH
聽 聽 聽7 TFONT
聽 聽 聽8 TREG32
聽 聽 聽9 TWEBVIEW2
聽 聽 10 TSTRUCT

Memory Analysis
===============
聽 聽 聽 642 Static variables

聽 聽Dynamic memory consume:
聽 聽 聽 Actual 聽Value: 聽 聽 聽 聽 聽0 bytes
聽 聽 聽 Highest Value: 聽 聽 聽 聽 聽0 bytes
Saludos
LEANDRO AREVALO
Bogot谩 (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sat Aug 24, 2024 05:32 AM

Leandro,

Hace falta una versi贸n actualizada de la Clase TWebView2

Tan pronto como est茅 terminado te env铆o las nuevas librerias de FWH para que lo puedas construir

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Mon Aug 26, 2024 07:27 PM
Recuperando los datos correctamente usando la nueva Clase TWebView2:
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWnd, cResult

聽 聽TEXT INTO cResult 
聽 聽 聽 [ document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:primerNombre' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:otrosNombres' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:primerApellido' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:segundoApellido' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:estado' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:dv' ).innerHTML ] 
聽 聽ENDTEXT 聽 聽 

聽 聽DEFINE WINDOW oWnd TITLE "Usando DIAN desde un webview" SIZE 1050, 700
聽 聽 
聽 聽oWebView = TWebView2():New( oWnd )
聽 聽oWebView:bOnNavigationCompleted = { | cUrl, hWebView | If( "sessionid" $ cUrl, oWebView:Eval( cResult ),) }

聽 聽oWebView:Navigate( "https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces" )
聽 聽oWebView:InjectJavascript( JavaScript() )
聽 聽// oWebView:OpenDevToolsWindow()
聽 聽oWebView:bOnEval = { | cJson, hWebView | If( cJson != "null" .and. cJson != "{}", MsgInfo( cJson ),) }
聽 聽oWebView:Eval( "consultaDIAN( '79760202' )" )

聽 聽ACTIVATE WINDOW oWnd CENTER ;
聽 聽 聽 ON RESIZE oWebView:SetSize( nWidth, nHeight )

聽 聽oWebView:End()

return nil

function Javascript()

聽 聽local cCode 

聽 聽TEXT INTO cCode 
聽 聽 聽 function consultaDIAN( numeroIdentificacion ) 
聽 聽 聽 {
聽 聽 聽 聽 聽var inputNIT = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit');
聽 聽 聽 聽 聽if (inputNIT) {
聽 聽 聽 聽 聽 聽 inputNIT.value = numeroIdentificacion;
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el campo de entrada para el NIT');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽} 聽 聽 
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽var botonBuscar = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:btnBuscar');
聽 聽 聽 聽 聽if (botonBuscar) {
聽 聽 聽 聽 聽 聽 botonBuscar.click();
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el bot贸n de b煤squeda');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽}
聽 聽 聽 }
聽 聽ENDTEXT

return cCode
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Mon Aug 26, 2024 07:32 PM
Lo pr贸ximo ser铆a ocultar la ventana y el webview para que no se vea como se obtiene la informaci贸n :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Tue Aug 27, 2024 04:16 PM
Excelente Antonio funciono de maravilla :D :D :D :D :D
Ahora nos falta el paso final :oops: :oops: :oops:
Como se hace para ocultar la ventana? y hacer el proceso sin que el usuario se de cuenta?

Por otro lado queremos entender el funcionamiento y el orden en que se ejecuta el proceso del lado del navegador y en que momento del lado de FW.
Code (fw): Select all Collapse
DEFINE WINDOW oWnd TITLE "Usando DIAN desde un webview" SIZE 1050, 700
聽 聽
聽 聽oWebView = TWebView2():New( oWnd )

聽 聽//TERCER PASO - Cuando se haya cargado la pagina por completo evaluamos la cadena cResult para que guarde en un array los datos que estan en los inputs
聽 聽//Lo que no entiendo es esta sintaxis [b]If( "sessionid" $ cUrl [/b], de donde recuperamos ese sessionid y para que sirve el signo $
聽 聽oWebView:bOnNavigationCompleted = { | cUrl, hWebView | If( "sessionid" $ cUrl, oWebView:Eval( cResult ),) }

聽 聽//PRIMER PASO - Hacemos el llamado a la url
聽 聽oWebView:Navigate( "https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces" )
聽 聽//SEGUNDO PASO - Le inyectamos el c贸digo java script al navegador "webview"
聽 聽oWebView:InjectJavascript( JavaScript() )
聽 聽//CUARTO PASO - Definimos el codeblock bOnEval, para ejecutar la acci贸n que necesitamos hacer de lado del FW, lo que no entiendo es en que momento se llena la variable cJson
聽 聽oWebView:bOnEval = { | cJson, hWebView | If( cJson != "null" .and. cJson != "{}", MsgInfo( cJson ),) }
聽 聽//QUINTO PASO - Evaluamos la funci贸n en javascript del lado del navegador que hab铆amos inyectado consultaDIAN la cual se encarga de ingresar el dato a buscar y hacer clic en el bot贸n para busqueda.
聽 聽oWebView:Eval( "consultaDIAN( '79760202' )" )

聽 聽ACTIVATE WINDOW oWnd CENTER ;
聽 聽 聽 ON RESIZE oWebView:SetSize( nWidth, nHeight )
Si es ese el orden?

Gracias de antemano.
Saludos
LEANDRO AREVALO
Bogot谩 (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Wed Aug 28, 2024 12:23 PM
Esta versi贸n casi que oculta todo el proceso:
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWnd, cResult

聽 聽TEXT INTO cResult 
聽 聽 聽 [ document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:primerNombre' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:otrosNombres' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:primerApellido' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:segundoApellido' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:estado' ).innerHTML,
聽 聽 聽 聽 document.getElementById( 'vistaConsultaEstadoRUT:formConsultaEstadoRUT:dv' ).innerHTML ] 
聽 聽ENDTEXT 聽 聽 

聽 聽DEFINE WINDOW oWnd TITLE "Usando DIAN desde un webview" SIZE 1050, 700
聽 聽oWnd:Hide()
聽 聽 
聽 聽oWebView = TWebView2():New( oWnd )
聽 聽oWebView:bOnNavigationCompleted = { | cUrl, hWebView | If( "sessionid" $ cUrl, oWebView:Eval( cResult ),) }

聽 聽oWebView:Navigate( "https://muisca.dian.gov.co/WebRutMuisca/DefConsultaEstadoRUT.faces" )
聽 聽oWebView:InjectJavascript( JavaScript() )
聽 聽// oWebView:OpenDevToolsWindow()
聽 聽oWebView:bOnEval = { | cJson, hWebView | If( cJson != "null" .and. cJson != "{}", ( MsgInfo( cJson ), oWnd:End() ),) }
聽 聽oWebView:Eval( "consultaDIAN( '79760202' )" )

聽 聽ACTIVATE WINDOW oWnd CENTER ;
聽 聽 聽 ON INIT oWnd:Hide() ;
聽 聽 聽 ON RESIZE oWebView:SetSize( nWidth, nHeight )

聽 聽oWebView:End()

return nil

function Javascript()

聽 聽local cCode 

聽 聽TEXT INTO cCode 
聽 聽 聽 function consultaDIAN( numeroIdentificacion ) 
聽 聽 聽 {
聽 聽 聽 聽 聽var inputNIT = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:numNit');
聽 聽 聽 聽 聽if (inputNIT) {
聽 聽 聽 聽 聽 聽 inputNIT.value = numeroIdentificacion;
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el campo de entrada para el NIT');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽} 聽 聽 
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽var botonBuscar = document.getElementById('vistaConsultaEstadoRUT:formConsultaEstadoRUT:btnBuscar');
聽 聽 聽 聽 聽if (botonBuscar) {
聽 聽 聽 聽 聽 聽 botonBuscar.click();
聽 聽 聽 聽 聽} else {
聽 聽 聽 聽 聽 聽 console.error('No se encontr贸 el bot贸n de b煤squeda');
聽 聽 聽 聽 聽 聽 return;
聽 聽 聽 聽 聽}
聽 聽 聽 }
聽 聽ENDTEXT

return cCode
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Wed Aug 28, 2024 12:25 PM

el operador $ es pertenencia en cadena, es decir:

"sessionid" $ cUrl // "sessionid" est谩 contenido en cUrl

es equivalente a:

At( "sessionid", cUrl ) != 0

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Wed Aug 28, 2024 12:31 PM

los procesos web suelen ser "as铆ncronos" es por esto que tenemos que usar codeblocks que ser谩n evaluados cuando suceda un determinado evento (en su momento)

bOnNavigationCompleted se evalua cada ve que cambiamos de url. Cuando buscamos a un usuario cambiamos a una url que usa "sessionid" en la url y gracias a esto sabemos que es en ese momento cuando tenemos ya en pantalla la informaci贸n que buscamos

Asi mismo, bOnEval se eval煤a cuando termina la llamada a oWebView:Eval(), nuevamente de forma as铆ncrona

bOnBind se evalua cuando se llama a SendToFWH() desde javascript // no usado en este ejemplo

la secuencia que usamos basicamente es:

  1. navegamos a una url

  2. inyectamos c贸digo javascript

  3. llamamos al c贸digo inyectado

  4. se cambia de url, detectamos el cambio y evaluamos una expresion javascript que nos da la informaci贸n que buscamos

todo esto teniendo en cuenta que son procesos as铆ncronos, luego esperamos a ciertos eventos que ejecutaran nuestros codeblocks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Fri Aug 30, 2024 07:57 PM
Excelente Antonio gracias por responder...

Perdoname no habia visto el POST, estaba escondido para mis ojos jejejejejeje

Ven por otro lado no se si no puedes ayudar para que se pueda ocultar el webview y que los usuarios no ven la forma en la que hacemos la consulta, solo que se actualizan las variables en la interfase de usuario :oops:

Gracias de antemano
Saludos
LEANDRO AREVALO
Bogot谩 (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sat Aug 31, 2024 06:11 AM
En este ejemplo: https://forums.fivetechsupport.com/viewtopic.php?p=272760#p272760

se oculta todo y solo se ve el resultado
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sat Aug 31, 2024 10:28 AM
Excelente Antonio, funciona de maravilla.

En serio que no note que me hab铆as contestado :oops: perdon

De todas formas como siempre muchas gracias.
Saludos
LEANDRO AREVALO
Bogot谩 (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]