WebBrowser1.Navigate () loads it into the RAD component window using the built-in IE component in Windows. What you do is answer the callback (for the browser component, double-click the OnDownloadComplete event) and save it in a file in this function. Fragments from the working code:
procedure TMainForm.WB_SaveAs_HTML(WB : TWebBrowser; const FileName : string) ; var PersistStream: IPersistStreamInit; Stream: IStream; FileStream: TFileStream; begin if not Assigned(WB.Document) then begin Logg('Document not loaded!') ; //'Logg' adds a line to a log file. Exit; end; PersistStream := WB.Document as IPersistStreamInit; FileStream := TFileStream.Create(FileName, fmCreate) ; try Stream := TStreamAdapter.Create(FileStream, soReference) as IStream; if Failed(PersistStream.Save(Stream, True)) then ShowMessage('SaveAs HTML fail!') ; finally FileStream.Free; end; end; (* WB_SaveAs_HTML *) procedure TMainForm.WebBrowser1DownloadComplete(Sender: TObject); begin if (WebBrowser1.Document<>nil)AND NOT(WebBrowser1.busy) then begin WB_SaveAs_HTML(WebBrowser1,'test.html'); //myStringList.loadFromFile('test.html'); //process it. end; end;
Note that some MIME types ("file"), such as JSON, open the "Save As ..." dialog box in IE, which stops reading and requires manual intervention.
Henrik Erlandsson
source share