delphi webbrowser 获取网页源码
时间:2014-05-09 16:20:59
收藏:0
阅读:424
转自 http://hi.baidu.com/delphidiary
转自 http://blog.sina.com.cn/s/blog_725fb194010150jh.html
//前面要加几个pas单元
uses Registry,ShellApi, WinInet,ShlObj,ComObj;
//========================================删COOKIES========================== procedure DelRegCache; var reg:TRegistry; begin reg:=Tregistry.create; reg.RootKey:=HKEY_CURRENT_USER; reg.DeleteKey(‘Software\Microsoft\Internet Explorer\TypedURLs‘); reg.Free; end; function GetCookiesFolder:string; var pidl:pItemIDList; buffer:array [ 0..255 ] of char ; begin SHGetSpecialFolderLocation( application.Handle , CSIDL_COOKIES, pidl); SHGetPathFromIDList(pidl, buffer); result:=strpas(buffer); end; function ShellDeleteFile(sFileName: string): Boolean; var FOS: TSHFileOpStruct; begin FillChar(FOS, SizeOf(FOS), 0); {记录清零} with FOS do begin wFunc := FO_DELETE;//删除 pFrom := PChar(sFileName); fFlags := FOF_NOCONFIRMATION; end; Result := (SHFileOperation(FOS) = 0); end; //删除cookies procedure DelCookie; var dir:string; begin try InternetSetOption(nil, INTERNET_OPTION_END_BROWSER_SESSION, nil, 0); dir:=GetCookiesFolder; ShellDeleteFile(dir+‘\*.txt‘+#0); //网上很多代码这里没有加最后的#0,在xp下经测试会报错 except abort; end; end; //========================================删COOKIES=========================
USES mshtml
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; 2 const pDisp: IDispatch; var URL: OleVariant); 3 var 4 i:Integer; 5 iall : IHTMLElement; 6 begin 7 if WebBrowser1.Application = pDisp then 8 begin 9 Memo1.Clear; 10 if Assigned(WebBrowser1.Document) then 11 begin 12 iall := (WebBrowser1.Document AS IHTMLDocument2).body; 13 while iall.parentElement <> nil do 14 begin 15 iall := iall.parentElement; 16 end; 17 Memo1.Text := Memo1.Text+iall.outerHTML; 18 end; 19 end; 20 end;
评论(0)