线程中如何判断form上的webbrowser页面读取完毕?或者请求多线程读取网页的代码——在线结分(50分)

  • 主题发起人 主题发起人 scdoudou
  • 开始时间 开始时间
S

scdoudou

Unregistered / Unconfirmed
GUEST, unregistred user!
线程中如何判断form上的webbrowser页面读取完毕?或者请求多线程读取网页的代码
 
查看状态了,
 
OnDocumentComplete事件
 
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;

 
后退
顶部