首页 > 代码库 > delphi webbrowser 获取网页源码
delphi webbrowser 获取网页源码
转自 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;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。