Cita:
Empezado por oscarac
lo hice de esta manera
se puede identificar la tabla con los elementos que contiene via delphi?
esta parte es la que me interesa, se que puedo buscar un texto y de ahi ir tanteando, pero pense que habria alguna otra forma?
|
Aquí te va una solución. Pero toma en cuenta lo que comenta
AgustinOrtu porque tan pronto cambien el formato de salida, tendrías que alterar tu código.
Estoy suponiendo que tu formulario contiene un component IdHTTP y un ListView. Defines entonces el método
Código Delphi
[-]
TForm1 = class(TForm)
public
procedure Consulta(Anio, Mes: String);
end;
Este método consultará el año y mes indicados (como cadenas) y llenará el ListView con los datos obtenidos:
Código Delphi
[-]
uses ActiveX, MSHTML, DateUtils;
const
URL = 'http://www.sunat.gob.pe/cl-at-ittipcam/tcS01Alias';
procedure TForm1.Consulta(Anio, Mes: String);
var
Params: TStrings;
Response: String;
Documento: OleVariant;
Tablas: OLeVariant;
Tabla: OleVariant;
Fila: OleVariant;
Celda: OleVariant;
Item: TListItem;
I, J: Integer;
begin
lvwDatos.Clear;
IdHTTP.Get(URL);
Params := TStringList.Create();
Params.Values['anho'] := Anio;
Params.Values['mes'] := Mes;
try
Response := IdHTTP.Post(URL, Params);
finally
Params.Free;
end;
Documento := coHTMLDocument.Create as IHTMLDocument;
Documento.Write(Response);
Documento.Close();
Tablas := Documento.getElementsByTagName('table');
Tabla := Tablas.item(1);
for I := 1 to Tabla.rows.length - 1 do
begin
Fila := Tabla.rows.item(I);
for J := 0 to (Fila.cells.length div 3) - 1 do
begin
Item := lvwDatos.Items.Add;
Celda := Fila.cells.item(3*J);
Item.Caption := Trim(Celda.innerText);
Celda := Fila.cells.item(3*J + 1);
Item.SubItems.Add(Trim(Celda.innerText));
Celda := Fila.cells.item(3*J + 2);
Item.SubItems.Add(Trim(Celda.innerText));
end;
end;
end;
LineComment Saludos