码迷,mamicode.com
首页 > 编程语言 > 详细

MFC webbrowser读取文档的meta分析

时间:2015-02-04 14:30:22      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

IDispatch* pDisp = NULL;
IDispatch* pDisp2 = NULL;
IHTMLDocument2 *pHtmlDoc2 = NULL;
IHTMLElementCollection* pCol;
IHTMLMetaElement *pMeta = NULL;
BSTR bUrl = NULL;
BSTR bstr = NULL; 
try {
    if ((pDisp = m_WebBrowser.get_Document()) &&
        SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2,(PVOID*)&pHtmlDoc2)) 
        && SUCCEEDED(pHtmlDoc2->get_all( &pCol)) && pCol
        )
    {
        //检查域名是www.test.com或www.test2.com的域名下, meta标签是否有myflag标记, 如果有则认为是正确的网页bIsGoodWebPage为TRUE
        pHtmlDoc2->get_URL(&bUrl);
        if(wcsstr((const wchar_t*)bUrl, L"www.test.com") == NULL 
            && wcsstr((const wchar_t*)bUrl, L"www.test2.com") == NULL)
        {
            bIsGoodWebPage = TRUE;
        }
        else
        {
            long eleLen = 0;
            pCol->get_length(&eleLen);
            IHTMLMetaElement* pMetaElement = NULL;
            VARIANT varIndex;
            HRESULT hr;
            for( int i=0; i< eleLen; i++)
            {
                VARIANT var2;
                varIndex.vt = VT_UINT;
                varIndex.lVal = i;
                VariantInit( &var2 );
                hr = pCol->item(varIndex, var2, &pDisp2);
                hr  = pDisp2->QueryInterface(IID_IHTMLMetaElement,(void**)&pMeta);
                if( hr == S_OK)
                {
                    if( SUCCEEDED(pMeta->get_httpEquiv(&bstr)) )
                    {
                        if(!wcscmp((const wchar_t*)bstr,L"keywords"))
                        {
                            bstr = NULL;
                            if(SUCCEEDED(pMeta->get_content(&bstr)))
                            {
                                if(!wcscmp((const wchar_t*)bstr, L"myflag"))
                                {
                                    bIsGoodWebPage = TRUE;
                                    break;
                                }
                            }
                        }    
                    }
                }
            }
        }
    }
}
catch (...)
{
    WBTRACE("Error\r\n");
}
SAFE_RELEASE(pMeta);
SAFE_RELEASE(pDisp2);
SAFE_RELEASE(pHtmlDoc2);
SAFE_RELEASE(pDisp);

 

MFC webbrowser读取文档的meta分析

标签:

原文地址:http://www.cnblogs.com/barrysgy/p/4272179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!