是這樣的,小弟想用Idhttp下載一個網站所有鏈接檔案,但是這個結構怎么設計好呢?
我感覺我這下面的結構有問題,而且效率也有問題,這個結構怎么設計好呢?
請大蝦幫看下,謝謝...
//回圈下載,整得整站html代碼
procedure TTestForm.Button8Click(Sender: TObject);
var
AddrList:TStringList; //網址清單
CurLink,LinkSource:String; //鏈接網頁的源代碼
ts1,ts2:TStringList;
i,j,k:Integer;
begin
//1.從首個入口網站取得源代碼
CurSite:='http://www.XXXX.com';//標記當前網址,用來網址規范化,尾部不帶/
LinkSource:=PageSource(CurSite);
try
//2.分析源代碼,取得初始鏈接地址
AddrList:=TStringList.Create;
ts1:==TStringList.Create;
ts2:==TStringList.Create;
AddrList:=PageLink(LinkSource,'href[^\s]*');
k:=0;
//ShowMessage(ts1.GetText);
//3.回圈每一個鏈接地址,直到所有的都執行完
while AddrList.Count<0 do
begin
LinkSource:=PageSource(AddrList.Strings[k]);//取得鏈接源代碼,PageSource為取得源代碼函式,回傳htm字串
ts1:=PageLink(LinkSource,'href[^\s]*');//取得源代碼的甩的鏈接,PageLink為正式表達,取得所有超鏈接串列Stringlist資料
//將鏈接添加到串列
if LinkSource<>'' then
begin
//分解出ts1,添加到陣列AddrList
for j := 0 to ts1.Count - 1 do
begin
if AddrList.IndexOf(Trim(ts1.Strings[i]))<0 then//當不存在時,添加進去
AddrList.Add(Trim(ts1.Strings[i]));
end;
end;
//保存檔案
ts2.add(LinkSource);
ts2.SaveToFile(k+'.htm');
//執行后洗掉當前記錄
AddrList.Delete(k);
Inc(k);
end;
finally
AddrList.Free;
ts1.free;
ts2.free;
end;
end;
uj5u.com熱心網友回復:
有沒路過的兄弟....uj5u.com熱心網友回復:
結構沒啥大問題,用多執行緒提升效率吧轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/83434.html
標籤:VCL組件開發及應用
上一篇:C++ 'father' : no appropriate default constructor available
