假设有两个窗体F1 F2 显示F1时、让F2的webbrowser加载某网页、同时F1内有timer控件检测F2的webbrowser状态、 我通过判断webbrowser的busy属性来确定是否加载完成、然而这行代码我通过//timer里、就拿说的例子 var html:string; begin if not f2.webbrowser.busy then begin html:=IHtmlDocument2(WebBrowser1.document).body.outerHTML;//就这里提示访问错误 end; end;难道说busy为false的时候、页面依旧没有加载完毕?那么如何才能判断页面是否已经成功载入了呢?
procedure TForm1.wbDownloadComplete(Sender: TObject);//寫到事件里是最常規的 begin if wb.ReadyState=3 then //通過交互進度判斷 html:= wb.OleObject.Document.documentElement.innerHTML;//這才是網頁全源碼, end;上面的 body.outerHTML; 僅僅是BODY里的內容。TITLE與樣式取不到
uses MSHTML;IHtmlDocument2(WebBrowser1.document).body.outerHTML
显示F1时、让F2的webbrowser加载某网页、同时F1内有timer控件检测F2的webbrowser状态、
我通过判断webbrowser的busy属性来确定是否加载完成、然而这行代码我通过//timer里、就拿说的例子
var
html:string;
begin
if not f2.webbrowser.busy then
begin
html:=IHtmlDocument2(WebBrowser1.document).body.outerHTML;//就这里提示访问错误
end;
end;难道说busy为false的时候、页面依旧没有加载完毕?那么如何才能判断页面是否已经成功载入了呢?
begin
if wb.ReadyState=3 then //通過交互進度判斷
html:= wb.OleObject.Document.documentElement.innerHTML;//這才是網頁全源碼,
end;上面的 body.outerHTML; 僅僅是BODY里的內容。TITLE與樣式取不到
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>标题</title>
<meta name="keywords" content=""/>
<meta name="description" content=""/>
这里嵌入了一些JS脚本
</head>
<script language="javascript">
//if (top.location != self.location)</script>
<body>
中间省略
</body>
</html> 然而我依然在timer里判断 if (frmMain.wb1.ReadyState = 3) and
(not frmMain.wb1.Busy) then
begin
Html:=frmMain.wb1.OleObject.Document.documentElement.innerHtml;
{上面这句话只能获得head部分的、其他的源码都看不到、原因不明}
Html:=IHtmlDocument2(WebBrowser1.document).body.outerHTML;
{上面这句依然提示内存访问出错...}
end;
这都是什么原因造成的呢?
{上面这句依然提示内存访问出错...}這句改成這樣試試!Html:=(wb.Document AS IHTMLDocument2).body.outerHTML;
采用
frmMain.wb1.OleObject.Document.documentElement.outerHtml;
的方法、获取的源码很奇怪、包含了html标签、可是html标签内竟然没有body标签、而且js脚本也一并被忽略掉了、、
Html:=(wb.Document AS IHTMLDocument2).body.outerHTML;
的方法也依然提示内存访问错误、、我访问的地址是:
http://www.19mayi.com/index.php/account/login
看了源码、这页面有相当一部分的内容在注释符中间、难道webbrowser就直接把注释中的HTML给忽略掉了?亦或是其他原因?
downok :boolean;
在f2.WB1.OnDocumentComplete判断网页下载完毕,
使用not WB1.Busy 或 WB1.ReadyState = READYSTATE_COMPLETE 或 WB1.Application = pDisp尝试
downok := True;f1.Time内
if downok then
try
Html := WB1.OleObject.document.documentelement.innerHtml;
downok := false;
exceptend;
[email protected] 13F
容我看看..
当我设置断点、想看看DownloadComplete的时候、竟然网页就打不开了、、
单步调试发现DownloadComplete发生了一次、不满足条件、之后DownloadComplete就没有再次触发过、程序则陷入假死、猜想可能是我系统原因、、
Xp Sp3 + IE 7