开发者

Extract Text from web page displayed in a TWebBrowser

开发者 https://www.devze.com 2022-12-18 13:31 出处:网络
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 b开发者_如何学编程e done & how can I d

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 b开发者_如何学编程e done & how can I do it?


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;


If your wanting to load this into a TRichEdit, then I suggest looking at the WPTools component which has the ability to load the data from an HTML stream, and export as RTF. I use this component to handle my internal email editor (which it appears is what your after).

0

精彩评论

暂无评论...
验证码 换一张
取 消