Ver Mensaje Individual
  #4  
Antiguo 27-05-2013
darkamerico darkamerico is offline
Miembro
 
Registrado: dic 2010
Posts: 273
Reputación: 16
darkamerico Va por buen camino
Thumbs up Solucionado

Mis estimados amigos, investigando logre dar con la solucion, chequeen el codigo:

Código Delphi [-]
function ObtenerWeb(webIP : string) : string;
var
  Response: TStringStream;
  HTTP: TIdHTTP;
begin
  Result := '';
  Response := TStringStream.Create('');
  try
    HTTP := TIdHTTP.Create(nil);
    try
      HTTP.Get(webIP, Response);
      if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
        Result := Response.DataString;
      end else begin
        // TODO -cLogging: add some logging
      end;
    finally
      HTTP.Free;
    end;
  finally
    Response.Free;
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
var
  doc: OleVariant;
  el: OleVariant;
  i: Integer;
  HTML:string;
begin
  with TIdHTTP.Create(nil) do
  try
    HTML:=ObtenerWeb('http://www.sbs.gob.pe/0/modulos/jer/jer_interna.aspx?are=0&pfl=0&jer=147');
    //HTML:=ObtenerWeb('http://localhost/dolar.html');
    doc := coHTMLDocument.Create as IHTMLDocument2;
    doc.write(HTML);
    doc.close;
    //ShowMessage(doc.body.innerHTML);
    for i := 0 to doc.body.all.length - 1 do
    begin
      el := doc.body.all.item(i);
      if (el.tagName = 'P') and (el.className = 'WEB_compra') then
        ShowMessage(el.innerText);
      if (el.tagName = 'P') and (el.className = 'WEB_venta') then
        ShowMessage(el.innerText);
    end;
  finally
    Free;
  end;
end;

Ahora, surje lo siguiente: Internet es muy lento en mi ciudad, por lo tanto, al pulsar este boton todo el programa se queda congelado, quisiera preguntar de que forma puedo realizar esta consulta en otro Thread de ejecucion, tal cual trabaja Ajax con sus llamadas asincronas...


Un abrazo a todos

Americo
Responder Con Cita