Урок на делфи. 86. Парсим сайт


задание на delphi. Задание на Delphi. Сделать парсинг сайта

unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AnimateWindow (handle, 5000, AW_BLEND);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Label1.Caption:=IntToStr(Screen.Width);
Label2.Caption:=IntToStr(Screen.Height);
Form1.Left:= (Screen.Width - Form1.Width) div 2;
Form1.Top:= (Screen.Height - Form1.Height) div 2;
AnimateWindow (handle, 5000, AW_BLEND );
end;
end.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bd:TStringList;
i,j,c:integer;
s:string;
metka:Boolean;
begin
Memo1.ScrollBars:=ssVertical;
Memo1.Clear;
bd:=TStringList.Create;
bd.LoadFromFile('..\..\bd.txt');
metka:=false;
Label1.Caption:='- '+IntToStr(bd.Count);
c:=0;
for I := 0 to bd.Count-1 do
begin
s:=bd[i];
for j := 0 to bd.Count-1 do
begin
if s=bd[j] then
c:=c+1;
end;
for j := 0 to Memo1.Lines.Count-1 do
begin
if pos (s+' = ',Memo1.Lines[j])>0 then
metka:=true;
end;
if (metka=false) then
Memo1.Lines.Add(s+' = '+IntToStr(c)) ;
c:=0;
metka:=false;
end;
Label2.Caption:='- '+IntToStr(Memo1.Lines.Count);
FreeAndNil(bd);
end;
end.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i,k:integer;
temp,csv:TStringList;
s,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12:string;
begin
Memo1.Clear;
Memo1.ScrollBars:=ssBoth;
temp:=TStringList.Create;
temp.Add(utf8String(IdHTTP1.get('http://www.finmarket.ru/shares/fmrt/d_mcxeq/?rid=3')));
temp.SaveToFile('table1.txt');
Memo1.Lines.AddStrings(temp);
temp.Text:=StringReplace(temp.Text,'target=_blank>',#13,[rfReplaceAll, rfIgnoreCase]);
temp.Text:=StringReplace(temp.Text,'',#13,[rfReplaceAll, rfIgnoreCase]);
temp.SaveToFile('table2.txt');
csv:=TStringList.Create;
for I := 0 to temp.Count-1 do
begin
k:=pos (' if k>0 then
begin
s:=temp[i];
p1:=Copy(s,1,k-1);
Delete(s,1,pos('align=right>',s)+11);
p2:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p3:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p4:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p5:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p6:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p7:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p8:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p9:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p10:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=right>',s)+11);
p11:=Copy(s,1,pos('',s)-1);
Delete(s,1,pos('align=center>',s)+12);
p12:=Copy(s,1,20);
csv.Add(p1+';'+p2+';'+p3+';'+p4+';'+p5+';'+p6+';'+p7+';'+p8+';'+p9+';'+p10+';'+p11+';'+p12);
end;
end;
Memo1.Clear;
Memo1.Lines.AddStrings(csv);
csv.SaveToFile('csv.txt');
FreeAndNil(temp);
FreeAndNil(csv);
end;
end.



Скачать