参考一下,对你有用,没时间再重写程序了!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1414973
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1408891
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, ComCtrls;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Panel1: TPanel;
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
procedure IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
procedure getLink(str:String);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
body:String;
begin
Memo1.Clear;
body:=idHTTP1.Get(Edit1.Text); //得到html源文件
//Memo1.Text:=body;
getLink(body);
end;
procedure TForm1.IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Max:= AWorkCountMax;
end;
procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position:= 0;
end;
procedure TForm1.IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
ProgressBar1.Position:= AWorkCount;
end;
procedure TForm1.getLink(str: String);
var
i,j:Integer;
isLink:Boolean;
tmpurl:String;
function geturl(linkStr:String):String;
var
eqpos,m,n,lsLen:Integer;
tmpLink:String;
begin
Result:='';
eqpos:=Pos('=',linkStr);
lsLen:=Length(linkStr);
if linkStr[eqpos+1]='"' then begin
for m := 0 to lsLen-1 do
begin
if linkStr[m+eqpos+2]='"' then break;
end;
tmpLink:=copy(linkStr,eqpos+2,m);
if ExtractFileExt(tmpLink)='.exe' then Result:=tmpLink;
end
else
begin
for n := 0 to lsLen-1 do
begin
if (linkStr[n+eqpos+1]=' ') or (linkStr[n+eqpos+1]='>') then break;
end;
tmpLink:=copy(linkStr,eqpos+1,n);
if ExtractFileExt(tmpLink)='.exe' then Result:=tmpLink;
end;
end;
begin
isLink:=false;
for i := 0 to Length(str)-1 do
begin
if str+str[i+1]='<a' then isLink:=true;
if str+str[i+1]+str[i+2]+str[i+3]='<src' then isLink:=true;
if isLink then begin
for j := 0 to Length(str)-i-1 do
begin
if str[i+j]='>' then begin
break;
end;
end;
tmpurl:=geturl(copy(str,i,j+1));
if Pos('exe',tmpurl)>0 then Memo1.Lines.Add(tmpurl);
isLink:=false;
end;
end;
end;
end.