如何通过IHTMLDocument2接口获取网页中的meta信息

sblsongdongf 2006-02-13 08:45:10
VC 7.0环境, IE
...全文
216 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2006-02-14
  • 打赏
  • 举报
回复
HRESULT TBaseWebBrowserPageletCtrl::GetMetaCollection(IHTMLElementCollection** pCollec, IHTMLDocument2* pDocument)
{
CComPtr<IDispatch> lDispatch;
CComQIPtr<IHTMLDocument2> lDocument;
HRESULT lResult;

if (pDocument == NULL)
{
if (!m_BrowserTree)
return E_FAIL;

lResult = m_BrowserTree->get_Document(&lDispatch);
lDocument = lDispatch;
lDispatch = NULL;
ASSERT(SUCCEEDED(lResult) && lDocument);
if (FAILED(lResult) || (lDocument == NULL))
return E_FAIL;
}
else
{
lDocument = pDocument;
}

CComPtr<IHTMLElementCollection> lCollec;

lResult = lDocument->get_all(&lCollec);
ASSERT(SUCCEEDED(lResult) && lCollec);

if (FAILED(lResult) || (lCollec == NULL))
return E_FAIL;

lResult = lCollec->tags(CComVariant("META"), &lDispatch);
return lDispatch->QueryInterface(pCollec);
}


HRESULT TBaseWebBrowserPageletCtrl::CheckMetaTags()
{
CComQIPtr<IHTMLElementCollection> lCollec;
CComQIPtr<IHTMLMetaElement> lMetaElement;
CComPtr<IDispatch> lDispatch;
HRESULT lResult;
long lIndex = 0;
long lLength = 1;

lResult = GetMetaCollection(&lCollec);

if (SUCCEEDED(lResult) && lCollec)
{
lResult = lCollec->get_length(&lLength);
ASSERT(SUCCEEDED(lResult));
}

while (lIndex < lLength)
{
if (lCollec)
{
lResult = lCollec->item(CComVariant(lIndex), CComVariant(), &lDispatch);
lMetaElement = lDispatch;
lDispatch = NULL;
ASSERT(SUCCEEDED(lResult) && lMetaElement);
}

if (SUCCEEDED(lResult) && lMetaElement)
{
//
CComBSTR lName;

lResult = lMetaElement->get_name(&lName);
if (SUCCEEDED(lResult)
&& lName
&& (!wcsicmp(CComBSTR(KEEBOO_PRODUCT_NAME), lName)
|| !wcsicmp(CComBSTR(KEEBOO_COMPANY), lName)))
{
CComBSTR lMetaContent;

lResult = lMetaElement->get_content(&lMetaContent);

if (SUCCEEDED(lResult) && lMetaContent)
{
if (!wcsicmp(L"no-stretch", lMetaContent))
{
m_bNoStretch = TRUE;
}
else if (!wcsicmp(L"no-cache", lMetaContent))
{
CComQIPtr<IPageletSink> lPageletSink(m_pControlSite);

if (lPageletSink)
{
CComObject<TDeleteCacheEntryCallback>* lCallback;
CComQIPtr<IPageletDestroyCallback> lCBInterface;

CComObject<TDeleteCacheEntryCallback>::CreateInstance(&lCallback);
lCallback->SetPage(getModel());

lCBInterface = lCallback;
lPageletSink->SetDestroyCallback(lCallback);
}
}
else
{
TModelPtr<TPropertyObjectModel> lProp;
TModelPtr<TContentModel> lContentModel;

if (!wcsicmp(L"online-reload", lMetaContent))
{
getModel()->getContent(&lContentModel);
GetModelProperty<TContentModel>(lContentModel, T_CONTENT_NETWORK_PROPERTIES, &lProp, TRUE);
ASSERT(lProp);

if (lProp)
lProp->putBooleanField("online-reload", true);
}
else if (!wcsicmp(L"online-flush", lMetaContent))
{
getModel()->getContent(&lContentModel);
GetModelProperty<TContentModel>(lContentModel, T_CONTENT_NETWORK_PROPERTIES, &lProp, TRUE);
ASSERT(lProp);

if (lProp)
lProp->putBooleanField("online-flush", true);
}
}
}
}
}

lIndex++;
}

return S_OK;
}

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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