BHO中存取网页IPersist

zhuang_bx 2010-08-23 03:20:09
Function GetHTML() As String
Dim oPI As IPersistStreamInit
Dim oPM As IPersistMemory
Dim mem() As String
Dim cbSize As Long

Set oPI = IE.Document
oPI.Save oPM, False


cbSize = oPM.GetSizeMax
ReDim mem(cbSize)
MsgBox cbSize
oPM.Save mem(0), False, cbSize
Set oPM = Nothing
ReDim mem(0)

End Function

上面这个代码出错,DELPHI版的我有

Function GetHTML2() As String ''''这个可以正常使用
Dim oPF As IPersistFile
Set oPF = IE.Document
oPF.Save "c:\1.htm", False
Set oPF = Nothing
End Function

上面这个可以,但是保存到文件了,我只想在内存中.....


...全文
248 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
橘子皮... 2010-09-15
  • 打赏
  • 举报
回复
楼上,请别无视我OK?
threenewbee 2010-09-15
  • 打赏
  • 举报
回复
很多人问这个,其实那段delphi程序本身就有问题。
橘子皮... 2010-09-14
  • 打赏
  • 举报
回复
各位,麻烦打断一下,问个问题
Dim oPF As IPersistFile
这个要引用什么东西才可以运行?
现在还是人类 2010-08-31
  • 打赏
  • 举报
回复
我才无语呢,你先看看MSDN吧
void NavigateComplete2(
[in] IDispatch* pDisp,
[in] Variant * URL
);

Fires after a navigation to a hyperlink is completed (on either a window or frameset element).

Returns S_OK to indicate that the operation was successful.
pDisp
Address of the frame'sIDispatch interface.
URL
String expression that evaluates to the URL, UNC file name, or PIDL that was navigated to. Note that this URL can be different from the URL that the browser was told to navigate to. One reason is that this URL is the canonicalized and qualified URL; for example, if an application specified a URL of "www.microsoft.com" in a call to the Navigate or Navigate2 method, the URL passed by NavigateComplete2 would be "http://www.microsoft.com/". Also, if the server has redirected the browser to a different URL, the redirected URL will be reflected here.
The URL parameter can be a PIDL in the case of a shell namespace entity for which there is no URL representation.

This event replaces the NavigateComplete and FrameNavigateComplete events, which should no longer be used. Internet Explorer 4.0 continues to fire the NavigateComplete and FrameNavigateComplete events for compatibility with Internet Explorer 3.0.

你只不过用的不是XMLHTTP对象来取得内容而已,用IPersistFile对象就不是我说的"很多其他的方法"了吗?
zhuang_bx 2010-08-31
  • 打赏
  • 举报
回复
呵,你要这么说我也无语。实践才有发言权。你试一下以下的代码,保存在1.htm中的是什么就知道了。

Private Sub IE_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Dim oPF As IPersistFile
Set oPF = IE.Document
oPF.Save "c:\1.htm", False
Set oPF = Nothing
End Sub
现在还是人类 2010-08-31
  • 打赏
  • 举报
回复
一个很简单的逻辑问题,比如有人叫你写一篇文章,但是你根本就没开始动笔写,这时候怎么可能存在你写的这篇文章在世界上呢?当然,这时候你从别人那买来一篇文章说是你的,当然也没问题,但这的确不是你自己所写的那篇文章呀。
就像你的要求,要你的BHO对象在尚未读目标网页内容前取得目标网页的内容,这是不行的。只有通过其他途径去预取得目标网页内容。虽然能取得,但并不是说你的BHO对象已经按正常的工作方式转到了目标网页。当然要取得某个URL地址的内容的方法有很多,我所说的XMLHTTP只是使用系统对象实现这个目的的其中的一个方法,当然还有很多其他的方法。对于DELPHI的对象我不是很清楚,但相信不会逃出这种逻辑概念。
zhuang_bx 2010-08-31
  • 打赏
  • 举报
回复
谢谢,我只是想知道VB是怎么用IPersistStreamInit来加载和保存IE.Document数据流的。

这是DELPHI版的,可以在NavigateComplete2事件(浏览器未显示网页时)中存取HTML的数据
function TIENotify.GetHTML:string;
var StrStream:TStringStream;
begin
StrStream:=TStringStream.Create('');
try
(FIEThis.Document as IPersistStreamInit).Save(TStreamadapter.Create(StrStream),false);
finally
Result:=StrStream.DataString ;
StrStream.Free ;
end;
end;

procedure TIENotify.SetHTML(s:string);
var StrStream:TStringStream;
begin
StrStream:=TStringStream.Create(s);
try
(FIEThis.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream));
finally
StrStream.Free ;
end;
end;
现在还是人类 2010-08-29
  • 打赏
  • 举报
回复
NavigateComplete2 是尚未执行网页跳转前的事件,既然尚未跳转,当然没有那个网页的内容信息啦。
如果你一定要在跳转前得到目标URL的网页内容,可以用XMLHTTP对象来取得目标网站的内容,使用方法
在我的博客中有范例,你可以自己去看一下
zhuang_bx 2010-08-28
  • 打赏
  • 举报
回复
DocumentComplete事件中是可以我知道

我是想要在NavigateComplete2事件中保存与载入HTML源码
现在还是人类 2010-08-25
  • 打赏
  • 举报
回复
你要在 DocumentComplete 事件中处理就可以
现在还是人类 2010-08-24
  • 打赏
  • 举报
回复
Function GetHTML2() As String
GetHTML2 = IE.Document.body.innerHTML
End Function
zhuang_bx 2010-08-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 supermanking 的回复:]
Function GetHTML2() As String
GetHTML2 = IE.Document.body.innerHTML
End Function
[/Quote]

你这个在NavigateComplete2事件中不行.

863

社区成员

发帖
与我相关
我的任务
社区描述
VB COM/DCOM/COM+
c++ 技术论坛(原bbs)
社区管理员
  • COM/DCOM/COM+社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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