多线程取网页源码?(100分)

  • 主题发起人 主题发起人 xuhao1
  • 开始时间 开始时间
X

xuhao1

Unregistered / Unconfirmed
GUEST, unregistred user!
多线程取网页源码?要源码,不要ICS控件
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ToolWin, ComCtrls, Buttons, ExtCtrls,jpeg,shellapi,filectrl,Wininet
,URLMon,ShlObj, ActiveX,DDEman,ComObj, CheckLst, Menus;

function Downloadhtml(const aUrl: string): Boolean;
var
i:integer;
list:Tstrings;
hSession: HINTERNET;
hService: HINTERNET;
abc,swfPath,ToFile:String;
lpBuffer: array[0..1024 + 1] of Char;
dwBytesRead: DWORD;
begin
Result := False;
list:=TStringlist.Create;
hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
if Assigned(hSession) then
begin
hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);
if Assigned(hService) then
try while True do
begin
dwBytesRead := 1024;
Application.ProcessMessages;
InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0 then break;
lpBuffer[dwBytesRead] := #0;
list.Add(lpBuffer);
//List.SaveToFile('c:/abc.txt');
//list.LoadFromFile('c:/abc.txt');
abc:=list.text;
list.text:=StringReplace ( abc,#13#10,'', [rfReplaceAll] );
//list.SaveToFile('c:/ajc.txt');
abc:=list.text;
abc:=StringReplace ( abc,'http',#13#10+'http', [rfReplaceAll] );
abc:=StringReplace ( abc,'href="','href="'+#13#10, [rfReplaceAll] );
abc:=StringReplace ( abc,'src="','src="'+#13#10, [rfReplaceAll] );
list.text:=StringReplace ( abc,'.swf','.swf'+#13#10, [rfReplaceAll] );
list.SaveToFile('c:/eee.txt');
//deletefile('c:/abc.txt');
end;
Result := True;
finally
InternetCloseHandle(hService);
end;
end;
finally
InternetCloseHandle(hSession);
end;

//
该方法能先下载网页内容再将所有的链接内容分离出来
你可以用
for i:=0 to list.count-1 do
begin
if pos('http',list.strings)<>0 then
showMessage(list.strings);//就是你要的地址了
end;

 
解决了,感谢wqhatnet
 
后退
顶部