• MFC webbrowser读取文档的meta分析


    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
    ");
    }
    SAFE_RELEASE(pMeta);
    SAFE_RELEASE(pDisp2);
    SAFE_RELEASE(pHtmlDoc2);
    SAFE_RELEASE(pDisp);
  • 相关阅读:
    java 无符号byte转换
    MySQL分区总结
    eclipse @override注解出错
    git 利用hook 实现服务器自动更新代码
    Centos 安装mysql
    Centos Python3安装共存
    chromedriver 代理设置(账号密码)
    PyQt5整体介绍
    python图片云
    PyPt5 浏览器实例
  • 原文地址:https://www.cnblogs.com/barrysgy/p/4272179.html
Copyright © 2020-2023  润新知