FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Capturar pagina html y recuperar resultado
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sat Oct 05, 2024 03:51 PM
As铆 funciona bien. Pru茅balo por favor:
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWndMain, 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 oWndMain TITLE "Usando DIAN desde un webview" SIZE 1050, 700 MDI

聽 聽DEFINE WINDOW oWnd MDICHILD OF oWndMain

聽 聽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 oWndMain 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: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 02:38 AM
Saludos Antonio

Abusando de que estas viendo esto, en Peru tenemos la SUNAT y es en su web que debemos consultar los datos de las empresas, si existen, si estan activas y si es Ok recuperar sus datos, la web de consulta es esta:
https://e-consultaruc.sunat.gob.pe/cl-ti-itmrconsruc/FrameCriterioBusquedaWeb.jsp
ahi un valor valido es mi RUC: 20508287781
como hago para pasando ese valor obtener los demas, que son: Numero de RUC (Incluye la razon social en este caso), Estado del Contribuyente, Condicion del Contribuyente y domicilio fiscal.
Trate de entender el ejemplo de Colombia, pero no veo como aplicarlo a este caso.
Gracias
Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 06:03 AM
Estimado Enrique,

Aqui lo tienes. La forma de obtener los valores de cResult es usando la IA. Se le da todo el HTML y le preguntas a la IA como obtener determinado valor usando javascript :-)

webviewruc.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWnd, cResult

聽 聽TEXT INTO cResult 
聽 聽 聽 [ document.querySelector('.list-group-item:nth-child(1) .col-sm-7 h4.list-group-item-heading').textContent,
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(2) .col-sm-7 p').textContent,
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(3) .col-sm-7 p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(4) .col-sm-3:nth-child(2) p').textContent,
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(4) .col-sm-3:nth-child(4) p').textContent,
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(5) .col-sm-7 p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(6) .col-sm-7 p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(7) .col-sm-7 p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(8) .col-sm-3 p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(8) .col-sm-3:nth-child(4) p').textContent.trim(),
聽 聽 聽 聽 document.querySelector('.list-group-item:nth-child(9) .col-sm-7 p').textContent.trim() ]
聽 聽ENDTEXT 聽 聽 

聽 聽DEFINE WINDOW oWnd TITLE "Usando SUNAT desde un webview" SIZE 1050, 700

聽 聽oWebView = TWebView2():New( oWnd )
聽 聽oWebView:bOnNavigationCompleted = { | cUrl, hWebView | If( "jcr" $ cUrl, oWebView:Eval( cResult ),) }

聽 聽oWebView:Navigate( "https://e-consultaruc.sunat.gob.pe/cl-ti-itmrconsruc/FrameCriterioBusquedaWeb.jsp" )
聽 聽oWebView:InjectJavascript( JavaScript() )
聽 聽// oWebView:OpenDevToolsWindow()
聽 聽oWebView:bOnEval = { | cJson, hWebView | If( cJson != "null" .and. cJson != "{}", ( MsgInfo( cJson ), oWnd:End() ),) }
聽 聽oWebView:Eval( "consultaRUC( '20508287781' )" )

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

聽 聽oWebView:End()

return nil

function Javascript()

聽 聽local cCode 

聽 聽TEXT INTO cCode 
聽 聽 聽 function consultaRUC( cRUC ) 
聽 聽 聽 {
聽 聽 聽 聽 聽var ruc = document.getElementById( 'txtRuc' );
聽 聽 聽 聽 聽var btnAceptar = document.getElementById( 'btnAceptar' ); 聽 
聽 聽 聽 聽 聽ruc.value = cRUC;
聽 聽 聽 聽 聽btnAceptar.click(); 聽 
聽 聽 聽 }
聽 聽ENDTEXT

return cCode
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8
Joined: Fri Dec 08, 2017 08:46 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 01:58 PM

Hola a todos,

Probando el codigo en tiempo de ejecuci贸n lanza este error

Time from start: 0 hours 0 mins 6 secs

Error occurred at: 06/10/2024, 08:56:14

Error description: Error BASE/1005 Message not found: TWEBVIEW2:_BONNAVIGATIONCOMPLETED

Args:

 [   1] = O   TWEBVIEW2

Esoy usando FWH2407 y compilando con VISUAL STUDIO para 64 BITS

Saludos

Jorge Antonio Cris贸stomo

Lima Per煤

Tel茅fono: +51 988460143
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 02:25 PM
Saludos Antonio

Funciona GRACIAS, cuando lo compilo solo (FWH 24.09 en 32Bits, BCC77 y xHb), esta todo Ok, pero cuando lo incluyo en mi sistema me sale el error abajo adjunto, alguna idea ??
Nota: debo mencionar que tube que comentar: METHOD SetWindowTheme( cSub, cIds ) INLINE _SetWindowTheme( ::hWnd, cSub, cIds ) porque me daba error al enlazar
Gracias

Application
===========
Path and name: D:\Gci\MySuite\MyContsys\MyContsys.EXE (32 bits)
Size: 3,689,984 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20201212)
FiveWin version: FWH 24.07
C compiler version: Borland/Embarcadero C++ 7.4 (32-bit)
Windows 11 64 Bits, version: 6.2, Build 9200

Time from start: 0 hours 0 mins 36 secs
Error occurred at: 06/10/2024, 09:18:01
Error description: Error BASE/1070 Error de argumento: ==
Args:
[ 1] = N 0
[ 2] = P 0xA60DD0C

Stack Calls
===========
Called from: .\source\classes\twebview2.prg => (b)WEBVIEW2_ONEVAL( 128 )
Called from: => ASCAN( 0 )
Called from: .\source\classes\twebview2.prg => WEBVIEW2_ONEVAL( 128 )
Called from: => WINRUN( 0 )
Called from: D:\Fwh\Fwh2407\source\classes\window.prg => TMDIFRAME:ACTIVATE( 1117 )
Called from: D:\Cv\contfive.prg => MAIN( 4353 )
Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 03:38 PM

El error de SetWindowTheme ocurre porque has de incluir la lib ( Borland ) uxtheme.lib en tu script de compilacion/linkado

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 06:45 PM
acrisostomo2017 wrote:Hola a todos,

Probando el codigo en tiempo de ejecuci贸n lanza este error

Time from start: 0 hours 0 mins 6 secs
Error occurred at: 06/10/2024, 08:56:14
Error description: Error BASE/1005 Message not found: TWEBVIEW2:_BONNAVIGATIONCOMPLETED
Args:
[ 1] = O TWEBVIEW2

Esoy usando FWH2407 y compilando con VISUAL STUDIO para 64 BITS
Necesitas la versi贸n de FWH 24.09
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: Sun Oct 06, 2024 06:47 PM
Enrrique Vertiz wrote:Saludos Antonio

Funciona GRACIAS, cuando lo compilo solo (FWH 24.09 en 32Bits, BCC77 y xHb), esta todo Ok, pero cuando lo incluyo en mi sistema me sale el error abajo adjunto, alguna idea ??
Nota: debo mencionar que tube que comentar: METHOD SetWindowTheme( cSub, cIds ) INLINE _SetWindowTheme( ::hWnd, cSub, cIds ) porque me daba error al enlazar
Gracias

Application
===========
Path and name: D:\Gci\MySuite\MyContsys\MyContsys.EXE (32 bits)
Size: 3,689,984 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20201212)
FiveWin version: FWH 24.07
C compiler version: Borland/Embarcadero C++ 7.4 (32-bit)
Windows 11 64 Bits, version: 6.2, Build 9200

Time from start: 0 hours 0 mins 36 secs
Error occurred at: 06/10/2024, 09:18:01
Error description: Error BASE/1070 Error de argumento: ==
Args:
[ 1] = N 0
[ 2] = P 0xA60DD0C

Stack Calls
===========
Called from: .\source\classes\twebview2.prg => (b)WEBVIEW2_ONEVAL( 128 )
Called from: => ASCAN( 0 )
Called from: .\source\classes\twebview2.prg => WEBVIEW2_ONEVAL( 128 )
Called from: => WINRUN( 0 )
Called from: D:\Fwh\Fwh2407\source\classes\window.prg => TMDIFRAME:ACTIVATE( 1117 )
Called from: D:\Cv\contfive.prg => MAIN( 4353 )
Estas usando ventanas MDI en tu aplicaci贸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: Sun Oct 06, 2024 06:48 PM
Enrrique Vertiz wrote:Saludos Antonio

Funciona GRACIAS, cuando lo compilo solo (FWH 24.09 en 32Bits, BCC77 y xHb), esta todo Ok, pero cuando lo incluyo en mi sistema me sale el error abajo adjunto, alguna idea ??
Nota: debo mencionar que tube que comentar: METHOD SetWindowTheme( cSub, cIds ) INLINE _SetWindowTheme( ::hWnd, cSub, cIds ) porque me daba error al enlazar
Gracias

Application
===========
Path and name: D:\Gci\MySuite\MyContsys\MyContsys.EXE (32 bits)
Size: 3,689,984 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20201212)
FiveWin version: FWH 24.07
C compiler version: Borland/Embarcadero C++ 7.4 (32-bit)
Windows 11 64 Bits, version: 6.2, Build 9200

Time from start: 0 hours 0 mins 36 secs
Error occurred at: 06/10/2024, 09:18:01
Error description: Error BASE/1070 Error de argumento: ==
Args:
[ 1] = N 0
[ 2] = P 0xA60DD0C

Stack Calls
===========
Called from: .\source\classes\twebview2.prg => (b)WEBVIEW2_ONEVAL( 128 )
Called from: => ASCAN( 0 )
Called from: .\source\classes\twebview2.prg => WEBVIEW2_ONEVAL( 128 )
Called from: => WINRUN( 0 )
Called from: D:\Fwh\Fwh2407\source\classes\window.prg => TMDIFRAME:ACTIVATE( 1117 )
Called from: D:\Cv\contfive.prg => MAIN( 4353 )
Este es el mismo error que nosotros tenemos, tambi茅n en el momento en que agregamos la funci贸n a la aplicaci贸n, por aparte funciona de manera correcta.
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: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 06:49 PM
Antonio Linares wrote:Lo est谩s usando en un entorno MDI, tal vez est茅 relacionado

Lo curioso es por que el handle del webview vale cero...
Si correcto, usamos ambiente MDI
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: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 06:53 PM
Antonio Linares wrote:As铆 funciona bien. Pru茅balo por favor:
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWebView

function Main()

聽 聽local oWndMain, 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 oWndMain TITLE "Usando DIAN desde un webview" SIZE 1050, 700 MDI

聽 聽DEFINE WINDOW oWnd MDICHILD OF oWndMain

聽 聽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 oWndMain 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
Nada mismo error

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: Sun Oct 06, 2024 07:05 PM

Leandro,

Est谩s usando la 24.09 ?

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: Sun Oct 06, 2024 07:08 PM
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: Sun Oct 06, 2024 07:29 PM
Antonio Linares wrote:Leandro,

Est谩s usando la 24.09 ?
Si correcto fw2409 64 bits
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: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Capturar pagina html y recuperar resultado
Posted: Sun Oct 06, 2024 07:31 PM
cnavarro wrote:El error de SetWindowTheme ocurre porque has de incluir la lib ( Borland ) uxtheme.lib en tu script de compilacion/linkado
Gracias !!! colocando la LIB indicada desaparecio el mensaje de error
Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m