Delphi WebBrowser access to Web source

Source: Internet
Author: User

Transfer from Http://hi.baidu.com/delphidiary

Transfer from http://blog.sina.com.cn/s/blog_725fb194010150jh.html

add several PAS units in front of//
uses Registry,shellapi, WinInet,shlobj, comobj ;
======================================== Delete cookies==========================procedureDelregcache;varReg:tregistry;beginReg:=tregistry.create; Reg. Rootkey:=HKEY_CURRENT_USER; Reg. DeleteKey ('software\microsoft\internet Explorer\TypedURLs'); Reg. Free;End;functionGetcookiesfolder:string;varpidl:pitemidlist; Buffer:Array[0..255] ofChar;beginshgetspecialfolderlocation (Application. Handle, Csidl_cookies, pidl); SHGetPathFromIDList (pidl, buffer); Result:=Strpas (buffer);End;functionShelldeletefile (sfilename:string): Boolean;varfos:tshfileopstruct;beginFillchar (FOS, SizeOf (FOS),0);{Record 0} withFos Do beginWfunc:= fo_delete;//Delete pfrom:=PChar (sFileName); Fflags:=fof_noconfirmation; End; Result:= (SHFileOperation (FOS) =0);End;//Delete CookiesprocedureDelcookie;vardir:string;begin TryInternetSetOption (Nil, Internet_option_end_browser_session,Nil,0); Dir:=Getcookiesfolder; Shelldeletefile (dir+'\*.txt'+#0); There's a lot of code on the web here without the last #0, the test will be error after XPexceptabort; End;End;======================================== Delete cookies=========================




USES mshtml

procedureTform1.webbrowser1documentcomplete (asender:tobject;2 ConstPdisp:idispatch;varurl:olevariant);3 var4 I:integer;5 iall:ihtmlelement;6 begin7 ifWebbrowser1.application = pdisp Then8 begin9 memo1.clear;Ten ifAssigned (webbrowser1.document) Then One begin AIall: =(webbrowser1.document as IHTMLDocument2). Body; - whileIall.parentelement <>Nil Do - begin theIall: =iall.parentelement; - End; -Memo1.text: = memo1.text+iall.outerhtml; - End; + End; - End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.