Extract Text from web page displayed in a TWebBrowser

M0-3E picture M0-3E · Jan 28, 2010 · Viewed 12.4k times · Source

I use delphi 7 and I would like to extract ONLY the text displayed in a webpage directly from a web page displayed in a TWebBrowser (no images....). Could it be done & how can I do it?

Answer

PA. picture PA. · Jan 28, 2010

I used the following...

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
 var
  Document: IHtmlDocument2;
begin
  edit1.text:=url;
  document := webbrowser1.document as IHtmlDocument2;
  memo2.lines.add(trim(document.body.innerhtml));  // to get html
  memo1.lines.add(trim(document.body.innertext));  // to get text
end;