如何得到一个包含框架的网页里面的所有标签文本?

mmkill 2004-08-14 05:04:16
如题,要包含框架的,直接用innertext可是得不到的啊
就让给100了,还可以多加分!
...全文
125 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengcg 2004-08-18
  • 打赏
  • 举报
回复
看看这个方法是不是比较容易理解一些(参考MSDN做出来的,调试通过):

procedure TMainForm.ToolButton56Click(Sender: TObject);
var
Index: Integer;
Document: IHTMLDocument2;
FrameIdx: OleVariant;
FrameDis: IDispatch;
FrameWin: IHTMLWindow2;
begin
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;

if WebBrowser1.Document = nil then Exit;
if WebBrowser1.Document.QueryInterface(IHTMLDocument2, Document) <> 0 then Exit;
if Document.frames.length > 0 then
begin
for Index := 0 to Document.frames.length - 1 do
begin
FrameIdx := Index;
FrameDis := Document.frames.item(FrameIdx);
if FrameDis.QueryInterface(IHTMLWindow2, FrameWin) <> 0 then Exit;
ShowMessage(FrameWin.document.body.outerHTML);
//FrameWin.document 就是你要的每个 Frame 的文档
end;
end;
end;

参考:http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/ifaces/document2/onclick.asp
mmkill 2004-08-16
  • 打赏
  • 举报
回复
应该可以直接取出来啊,上面代码看不明白啊
蒋晟 2004-08-15
  • 打赏
  • 举报
回复
Q196340 HOWTO: Get the WebBrowser Object Model of an HTML Frame

The following code demonstrates how to access the WebBrowser Object Model of frames in an HTML page to refresh the contents of each frame.

The most important piece of the code uses the IOleContainer::EnumObjects method of the HTML Document object to enumerate embeddings on the page. Each of these embeddings represents a control on the page. By querying each control object for IWebBrowser2, this code can determine whether the control is a sub-frame. And IWebBrowser2 represents the WebBrowser Object Model; if QueryInterface succeeds for this interface, the result is a reference to the WebBrowser Object Model.


// Get the IDispatch of the document
LPDISPATCH lpDisp = NULL;
lpDisp = m_webBrowser.GetDocument();

if (lpDisp)
{
IOleContainer* pContainer;

// Get the container
HRESULT hr = lpDisp->QueryInterface(IID_IOleContainer,
(void**)&pContainer);
lpDisp->Release();

if (FAILED(hr))
return hr;

IEnumUnknown* pEnumerator;

// Get an enumerator for the frames
hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
pContainer->Release();

if (FAILED(hr))
return hr;

IUnknown* pUnk;
ULONG uFetched;

// Enumerate and refresh all the frames
for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)
{
// QI for IWebBrowser here to see if we have an embedded browser
IWebBrowser2* pBrowser;

hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);
pUnk->Release();

if (SUCCEEDED(hr))
{
// Refresh the frame
pBrowser->Refresh();
pBrowser->Release();
}
}

pEnumerator->Release();
}
NOTE: ActiveX controls hosted in an HTML page can use this technique in a similar manner. In general, an ActiveX control that accesses the unsafe WebBrowser Object Model is not safe for scripting and should implement IObjectSafety interface accordingly for security.


zhengcg 2004-08-15
  • 打赏
  • 举报
回复
在 OnBeforeNavigate2 事件中,URL 参数会让你看到浏览一个框架页面所有的 URL,在 OnNavigateComplete2 事件中也可以。
你再分别浏览这些 URL ,就可以得到你要的所有标签文本了。虽然麻烦一点,但是至少解决了问题了。希望对你有用。
mmkill 2004-08-15
  • 打赏
  • 举报
回复
楼上的兄弟:
你怎么做的,可否分享一下,打开一下思路!
zhengcg 2004-08-14
  • 打赏
  • 举报
回复
我也想知道!
不过我自己目前是先用再发送那个需要分析的框架里子页面 URL 的方式解决的,反正因为缓存的关系,都是很快的。
纯冰糖 2004-08-14
  • 打赏
  • 举报
回复
IIE....接口
纯冰糖 2004-08-14
  • 打赏
  • 举报
回复
com原理的IInterFace...接口吧,忘记了

1,593

社区成员

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

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