【问题标题】:Extract Text from web page displayed in a TWebBrowser从 TWebBrowser 中显示的网页中提取文本
【发布时间】:2010-01-28 13:53:39
【问题描述】:

我使用 delphi 7,我想直接从 TWebBrowser 中显示的网页中提取网页中显示的文本(无图像....)。可以做吗?我该怎么做?

【问题讨论】:

    标签: delphi twebbrowser


    【解决方案1】:

    我使用了以下...

    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;
    

    【讨论】:

    • 谢谢 PA:这正是我需要做的!我想将文本复制到 TRichedit 中:有什么方法可以保持文本的格式(粗体,H1 ...)?
    • 您可能需要删除所有 标签并将 de html 显示回浏览器。
    【解决方案2】:

    如果您想将其加载到 TRichEdit 中,那么我建议查看WPTools 组件,该组件能够从 HTML 流中加载数据并导出为 RTF。我使用这个组件来处理我的内部电子邮件编辑器(它看起来就是你想要的)。

    【讨论】:

      猜你喜欢
      • 2020-05-17
      • 2020-09-03
      • 2018-04-03
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多