温柔一刀 (2000-06-18 19:02:00) <br>urlmon实现了urlmon.dll的com接口,<br>可以用来让你编的ActiveForm能够控制它的宿主浏览器,例如:<br><br>procedure TMyActiveForm.btRedirectClick(Sender: TObject);<br>begin<br>HLinkNavigateString(IUnknown(VCLComObject),'http://www.myserver.com');<br>end;<br><br>可以实现redirect到另一个地址,其中HLinkNavigateString是urlmon中的函数。 <br> <br><br><br><br>天真 (2002-05-09 17:46:00) <br>关于把网页,以及与网页相关的都保存到硬盘中!<br>这个答案如下:例子的效果把www.sina.com.cn的网页保存下来!:)<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,nmhttp,urlmon,<br> StdCtrls, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> Memo2: TMemo;<br> Splitter1: TSplitter;<br> procedure Button1Click(Sender: TObject);<br> private<br> procedure savedata(url,memo:string);<br> function dealwith(url,baseurl:string):string; //处理网页路径<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.savedata(url,memo:string);<br>function DownloadFile(Source, Dest: string): Boolean;<br>begin<br> try<br> Result:=UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;<br> except<br> Result:=False;<br> end;<br>end;<br><br>function getfilename(s:string):string;<br>var i:integer;<br>begin<br> for i:=length(s) downto 1 do<br> begin<br> if (s='/')or(s='/') then<br> break;<br> end;<br> result:=copy(s,i+1,length(s)-i);<br>end;<br><br>var i:integer;<br> imagelist:tstringlist;<br> bmplist:tstringlist;<br> tempmemo:string;<br> beginpos,endpos:integer;<br> path:string;<br> s:string;<br> memorystream:tmemorystream;<br>begin<br><br> bmplist:=tstringlist.Create ;<br> bmplist.Add('.bmp');<br> bmplist.Add('.jpg');<br> bmplist.Add('.swf');<br> bmplist.Add('.gif');<br><br> path:='d:/download/';<br> tempmemo:=memo;<br> imagelist:=tstringlist.create;<br> try<br> while pos('src=',memo)>0 do<br> begin<br> beginpos:=pos('src=',memo)+4;<br> while (memo[beginpos]=' ') or (memo[beginpos]='"') do<br> begin<br> inc(beginpos);<br> end;<br> endpos:=beginpos+1;<br> while (memo[endpos]<>' ') and (memo[endpos]<>'"')and (memo[endpos]<>'>')do<br> begin<br> inc(endpos);<br> end;<br>// s:=copy(memo,beginpos,endpos-beginpos);<br> s:=dealwith(copy(memo,beginpos,endpos-beginpos),'www.sina.com.cn');<br>// showmessage(s);<br> if (imagelist.indexof(s)=-1)or(imagelist=nil) then<br> begin<br> imagelist.Add(s);<br> DownloadFile(s,'d:/download/'+getfilename(s));<br> end;<br> delete(memo,1,endpos);<br> end;<br> except<br> showmessage(inttostr(beginpos)+','+inttostr(endpos));<br> end;<br> showmessage(inttostr(imagelist.count));<br> for i :=0 to imagelist.count-1 do<br> begin<br> memo1.text:=stringreplace(memo1.text,imagelist.strings,getfilename(imagelist.strings),[rfReplaceAll]);<br> end;<br><br> memorystream:=tmemorystream.Create ;<br> memorystream.Position :=0;<br> imagelist.Free;<br> bmplist.Free ;<br> memorystream.Free ;<br> memo1.Lines.SaveToFile('d:/download/index.htm');<br> showmessage('ok');<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var s:string;<br> nmhttp:tnmhttp;<br>begin<br> //建立nmhttp<br> nmhttp:=tnmhttp.Create(nil);<br> NMHTTP.InputFileMode := FALSE;<br> NMHTTP.OutputFileMode := FALSE;<br>// NMHTTP.ReportLevel := Status_Basic;<br> try<br> nmhttp.Get('www.sina.com.cn');<br> s:=nmhttp.body;<br> except<br> end;<br> memo1.text:=s;<br><br> savedata('sss',s);<br><br>end;<br><br>function Tform1.dealwith(url,baseurl:string):string; //处理网页路径<br>var i:integer;<br> beginpos:integer;<br>begin<br> URL:=stringreplace(url,'"','',[rfReplaceAll]);<br> if url[1]+url[2]+url[3]+url[4]+url[5]+url[6]+url[7]='http://' then<br> dealwith:=url;<br><br> URL:=stringreplace(url,'/','/',[rfReplaceAll]);<br><br> if pos(' ',url)<>0 then<br> begin<br> url:=copy(url,1, pos(' ',url)-1);<br> end;<br><br> for i:=length(baseurl) downto 1 do<br> begin<br> if baseurl='/' then<br> BEGIN<br> break;<br> END;<br> end;<br><br> IF I<>1 THEN<br> baseurl:=copy(baseurl,1,i)<br> ELSE<br> BASEURL:=BASEURL+'/';<br><br> if ((pos('.',url)<>0)and(pos('./',url)=0)and(url[1]<>'/')) or (pos('www.',url)<>0) then<br> dealwith:=url;<br><br> if (pos('../',url)=0)AND (POS('./',URL)=0) then //没有指定目录//??要改改<br> begin<br> if url[1]='/' then<br> url:=copy(url,2,length(url)-1);<br> dealwith:=baseurl+url;<br> end<br> else<br> begin<br> i:=length(baseurl)-1;<br> while pos('../',url)<>0 do<br> begin<br> beginpos:=pos('../',url);<br> delete(url,1,beginpos+2);<br> while i>=1 do<br> begin<br> if baseurl='/' then<br> begin<br> dec(i);<br> break;<br> end;<br> dec(i);<br> end;<br> end;<br> dealwith:=copy(baseurl,1,i)+'/'+url;<br> end;<br> dealwith:=url;<br>end;<br><br>end.<br><br> <br>------------------<br>随便找了一下,只有这点资料。