AI摘要

本文介绍了如何使用Delphi的WebBrowser组件提取网页的HTML源码。具体方法是在WebBrowser的DocumentComplete事件中,通过访问IHTMLDocument2接口获取网页的body元素,然后逐级向上遍历至最顶层元素,最后将顶层元素的outerHTML属性赋值给Memo控件以显示完整的HTML源码。
本文介绍了如何使用
[delphi WebBrowser] WebBrowser 提取html源码

uses mshtml;

procedure TForm1.wb1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
i:Integer;
iall : IHTMLElement;
begin
if wb1.Application = pDisp then
begin
mmo1.Clear;
if Assigned(wb1.Document) then
begin
iall := (wb1.Document AS IHTMLDocument2).body;
while iall.parentElement <> nil do
begin
iall := iall.parentElement;
end;
mmo1.Text := mmo1.Text+iall.outerHTML;
end;
end;
end;



最后修改:2013 年 01 月 31 日
点赞的人是最酷的