agentweb.prg

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
Contact:

agentweb.prg

Post by Antonio Linares »

agentweb.prg

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oWnd, oWebView

   DEFINE WINDOW oWnd TITLE "Agent Web" SIZE 1500, 1000

   oWebView = TWebView2():New( oWnd )
   oWebView:bOnNavigationCompleted = { | cUrl | oWebView:InjectJavascript( JSSearch() + ;
                                                If( "search" $ cUrl, "WebResults();", "WebSearch( 'fivewin' );" ) ) }
   oWebView:bOnBind = { | aData | XBrowse( aData[ 1 ] ) }
   oWebView:Navigate( "https://www.google.com" )
   oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
   // oWebView:OpenDevToolsWindow( .T. )

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

return nil

function JSSearch()

    local cCode 
 
    TEXT INTO cCode 
    function WebSearch( cText ) 
    {
       document.getElementById( "APjFqb" ).value = cText;
       document.querySelector( "input[name='btnK']" ).click();     
    }

    function WebResults()
    {
      const divs = document.querySelectorAll('div.N54PNb.BToiNc.cvP2Ce');
      let resultados = [];
     
      for (const div of divs) {
            // Obtener la URL
            const link = div.querySelector('a.rTyHce.jgWGIe');
            const url = link ? link.getAttribute('href') : '';
   
            // Obtener el texto principal (título)
            const linkDiv = div.querySelector('div[role="link"]');
            const span = linkDiv ? linkDiv.querySelector('span') : null;
            const textoPrincipal = span ? span.textContent.trim() : '';
   
            // Obtener el texto descriptivo
            const descripcionDiv = div.querySelector('div.VwiC3b.tZESfb.p4wth.r025kc.hJNv6b.Hdw6tb');
            const descripcion = descripcionDiv ? descripcionDiv.textContent.trim() : '';
   
            // Obtener el SVG como ícono
            const svgElement = div.querySelector('svg');
            const icono = svgElement ? svgElement.outerHTML : '<span class="default-icon">📍</span>';
           
            if (url && url.trim() !== '') {
               resultados.push([url, textoPrincipal, descripcion, icono]);
            }    
      }
     
      SendToFWH( resultados );
    }

    ENDTEXT
 
 return cCode
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
Contact:

Re: agentweb.prg

Post by Antonio Linares »

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply