Fórum Pagina HTML X Arquivo Texto #349337

21/11/2007

0

Boa tarde a todos,

Estou precisando salvar um código fonte de uma página HTML como texto para poder retirar o que preciso. Já vizualizei a Video Aula más ainda não consegui fazer o que preciso

Pagina := idhttp.Get(´http://www.cip-bancos.org.br/detalhe.aspx?secao=21´);

Preciso que esta variável página vire um arquivo texto para trabalhar linha a linha neste arquivo.

Portanto preciso saber como faço para salvar a variável página em arquivo texto.

Algo assim algumacoisa.Savetofile(Pagina)


Ferreia2

Ferreia2

Responder

Posts

24/11/2007

Luciano.lirio

FerreiA2,

cara fiz a primeira parte para vc ver o restante é só fazer com base nesse código.

function Space(_qtd:Integer;_cpo:string):string;
begin
  if copy(inttostr(_qtd),1,1)=´-´ then
    begin
      _qtd:=strtoint(copy(inttostr(_qtd),2,length(inttostr(_qtd))-1));
      space:=_cpo+stringofchar(´ ´,_qtd-length(_cpo));
    end
  else
    space:=stringofchar(´ ´,_qtd-length(_cpo))+_cpo;
end;

function PegaCampo(pStr: String): String;
begin
  repeat
    Delete(pStr,1,Pos(´>´,pStr));
    pStr := Trim(pStr);
  until (Copy(pStr,1,1) <> ´<´);
  Result := Trim(Copy(pStr,1,Pos(´<´,pStr)-1));
  if Result = ´&nbsp;´ then
    Result := ´´;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Html: TStringList;
  Texto: TStringList;
  Linha: String;
  I: Integer;
  CpoLin: Byte;
  NumLin: Byte;
  Campos: Array[0..5] of String;
begin

  Html := TStringList.Create;
  Html.Text := idhttp.Get(´http://www.cip-bancos.org.br/detalhe.aspx?secao=21´);
  //Html.SaveToFile(´c:\teste.html´);
  //Html.LoadFromFile(´c:\teste.html´);

  for I := 0 to Html.Count-1 do
    if Trim(Html[I]) = ´<TBODY>´ then
      Break;

  NumLin := 6;
  CpoLin := 0;
  Texto := TStringList.Create;
  for I := I+1 to Html.Count-1 do
  begin
    if Pos(´<TR style´,Html[I]) > 0 then CpoLin := 0;
    if Pos(´<TD class=xl111´,Html[I]) > 0 then Break;
    if Pos(´<TD class=xl158´,Html[I]) > 0 then Continue;

    if Pos(´<TD class=x´,Html[I]) > 0 then
    begin
      Campos[CpoLin] := PegaCampo(Html[I]);
      Inc(CpoLin);
      if CpoLin = NumLin then
        Texto.Add(Space(-08,Campos[0])+´;´+
                  Space(-08,Campos[1])+´;´+
                  Space(-12,Campos[2])+´;´+
                  Space(-08,Campos[3])+´;´+
                  Space(-08,Campos[4])+´;´+
                  Campos[5]);
    end;
  end;
  Texto.SaveToFile(´c:\teste.txt´);
  Texto.Free;
  Html.Free;
  ShowMessage(´Ok´);
end;




Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar