WebBrowser的问题,用什么方法获得框架中的内容?

GDU 2003-07-13 10:06:25
哪位知道帮帮忙哈、、、、、
...全文
124 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eastunfail 2003-07-14
  • 打赏
  • 举报
回复
我的代码可以得到整个HTML源代码。不过上面的有点问题,呵呵。掉了i的声明,重新写:
function GetHTML(Document:IHTMLDocument2):String;
var i:integer
IDisp:IDispatch;
pElement:IHTMLElement;
begin
for I := 0 to Document.all.length - 1 do // Iterate
begin
IDisp:=Document.all.item(i,i);
IDisp.QueryInterface(IID_IHTMLElement,pElement);
if CompareText(pElement.tagName,'HTML')=0 then
begin
Result :=pElement.outerHTML;
exit;
end;
end; // for
end;
Eastunfail 2003-07-14
  • 打赏
  • 举报
回复
function GetHTML(Document:IHTMLDocument2):String;
var IDisp:IDispatch;
pElement:IHTMLElement;
begin
for I := 0 to Document.all.length - 1 do // Iterate
begin
IDisp:=Document.all.item(i,i);
IDisp.QueryInterface(IID_IHTMLElement,pElement);
if CompareText(pElement.tagName,'HTML')=0 then
begin
Result :=pElement.outerHTML;
exit;
end;
end; // for
end;
Eastunfail 2003-07-14
  • 打赏
  • 举报
回复
这个代码支能够得到body里面的代码。。。。。。
yang6130 2003-07-13
  • 打赏
  • 举报
回复
获得网页源码
http://expert.csdn.net/Expert/topic/1991/1991829.xml?temp=.9192163
implementation
uses shellapi,SHDocVw,activex;
{$R *.dfm}

function WB_GetHTMLCode(WebBrowser: TWebBrowser; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
ss: TStringStream;
sa: IStream;
s: string;
begin
result:=false;
ps := WebBrowser.Document as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa := TStreamAdapter.Create(ss, soReference) as IStream;
try
Result := Succeeded(ps.Save(sa, True));
except
end;
if Result then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end;

//WB1.Navigate('http://cn.yahoo.com');
procedure TForm1.Button3Click(Sender: TObject);
begin
if WB_GetHTMLCODE(WB1,memo1.Lines) then ....
end;
sixgj 2003-07-13
  • 打赏
  • 举报
回复
不懂,帮你顶顶……
GDU 2003-07-13
  • 打赏
  • 举报
回复
To:yang6130(沧海@月明)

这样获得的内容里,不包括网页中的框架的

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧