在Windows mobile 6.0中获取网页文档

发布于 2024-08-13 19:44:22 字数 1323 浏览 6 评论 0原文

在互联网上进行大量搜索后,我们发现以下代码仅将网页的正文部分加载到网络浏览器控件上,

IPIEHTMLDocument2 *pHTMLDocument;

IPIEHTMLElement* pBodyElement; 

CComPtr<IDispatch> spDispDoc;

HRESULT res = m_spWebBrowser2->get_Document(&spDispDoc);


if(SUCCEEDED(res))
{
    spDispDoc->QueryInterface( __uuidof(IPIEHTMLDocument2), (void**)&pHTMLDocument);

    WCHAR szText[256];
    DISPID id;
    OLECHAR FAR* szTemp;

    // store "body"
    szTemp = szText;
    StringCchPrintf(szText, 256, L"body", id);

    // get the body
    pHTMLDocument->GetIDsOfNames(IID_NULL, &szTemp, 1, LOCALE_USER_DEFAULT, &id);

    VARIANT varResult;
    varResult.vt = VT_DISPATCH;
    VARIANT FAR *pVarResult = &varResult;
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};

    pHTMLDocument->Invoke(id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispparamsNoArgs, pVarResult, NULL, NULL);

    BSTR bodyValue;

    if( NULL != pVarResult->pdispVal)
    {
        pVarResult->pdispVal->QueryInterface(IID_IPIEHTMLElement, (void**)&pBodyElement);

        pBodyElement->get_innerHTML(&bodyValue);
    }         
} 

但是现在我们如何从加载的网页中获取剩余的头部和其他标记文档文本, 即使我们尝试将“head”字符串传递给 GetIDsOfNames() 方法,它也会传递失败值,所以我们感到震惊。 请向我们提供在windows mobile 6.0中访问/提取整个网页内容的方法

谢谢, 拉马南德·巴特.

After searching lot on the internet we have found following code to get only body part of the web page loaded onto web browser control

IPIEHTMLDocument2 *pHTMLDocument;

IPIEHTMLElement* pBodyElement; 

CComPtr<IDispatch> spDispDoc;

HRESULT res = m_spWebBrowser2->get_Document(&spDispDoc);


if(SUCCEEDED(res))
{
    spDispDoc->QueryInterface( __uuidof(IPIEHTMLDocument2), (void**)&pHTMLDocument);

    WCHAR szText[256];
    DISPID id;
    OLECHAR FAR* szTemp;

    // store "body"
    szTemp = szText;
    StringCchPrintf(szText, 256, L"body", id);

    // get the body
    pHTMLDocument->GetIDsOfNames(IID_NULL, &szTemp, 1, LOCALE_USER_DEFAULT, &id);

    VARIANT varResult;
    varResult.vt = VT_DISPATCH;
    VARIANT FAR *pVarResult = &varResult;
    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};

    pHTMLDocument->Invoke(id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispparamsNoArgs, pVarResult, NULL, NULL);

    BSTR bodyValue;

    if( NULL != pVarResult->pdispVal)
    {
        pVarResult->pdispVal->QueryInterface(IID_IPIEHTMLElement, (void**)&pBodyElement);

        pBodyElement->get_innerHTML(&bodyValue);
    }         
} 

But now how we get the remaining head and other tag document text from the loaded web page,
even we have tried passing "head" string to the GetIDsOfNames() method and it passes fail value, so we are struck.
Please provide us the method to access/ extract entire web page content in windows mobile 6.0

Thanks,
Ramanand Bhat.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早茶月光 2024-08-20 19:44:22
void  CBrowserWindow::ExtractWebPageDoc()

{
HRESULT                         hrResult           = E_FAIL;    
IDispatch                      *pIDisp             = NULL;
IPIEHTMLDocument3              *pIHTMLDocument     = NULL;
IPIEHTMLElementCollection      *pHTMLElementcol    = NULL;
IPIEHTMLImgElement             *pHTMLImgElement    = NULL; 


hrResult = m_spIWebBrowser2->get_Document( &pIDisp);
if (NULL != pIDisp)
{
    hrResult = pIDisp->QueryInterface( __uuidof(IPIEHTMLDocument3), (void**)&pIHTMLDocument);
    if( NULL != pIHTMLDocument)
    {
        IPIEHTMLElement* pElement = NULL;
        CComBSTR pHTMLElement;

        hrResult = pIHTMLDocument->get_documentElement( &pElement);
        if (SUCCEEDED(hrResult)) 
        {                               
            pElement->get_innerHTML(&pHTMLElement.m_str);
            SaveToHTMLFile( pHTMLElement);
        }

        hrResult = pIHTMLDocument->get_images( &pHTMLElementcol);
        if (NULL != pHTMLElementcol)
        {
            CComBSTR  strImage;
            VARIANT vtBase, vtIndex;
            long pHTMLElementCollectionLength = 0;

            VariantInit( &vtBase);
            vtIndex.vt = VT_UINT;

            hrResult = pHTMLElementcol->get_length( &pHTMLElementCollectionLength);
            for (int ilen = 0; ilen < (int)pHTMLElementCollectionLength ; ilen++)
            {           
                vtIndex.lVal = ilen;

                pIDisp = NULL;
                hrResult =  pHTMLElementcol->item( vtBase, vtIndex , &pIDisp);
                if (NULL != pIDisp)
                {
                    hrResult = pIDisp->QueryInterface( __uuidof(IPIEHTMLImgElement), (void**)&pHTMLImgElement);

                    if (NULL != pHTMLImgElement)
                    //CComQIPtr<IPIEHTMLImgElement> imgElement( pIDisp);
                    //imgElement->get_src( &strImage.m_str);    //I get it here :)
                    pHTMLImgElement->get_src( &strImage.m_str);
                }
            }
        }
    }
}

上述

代码获取windows mobile设备上的整个网页内容。

void  CBrowserWindow::ExtractWebPageDoc()

{
HRESULT                         hrResult           = E_FAIL;    
IDispatch                      *pIDisp             = NULL;
IPIEHTMLDocument3              *pIHTMLDocument     = NULL;
IPIEHTMLElementCollection      *pHTMLElementcol    = NULL;
IPIEHTMLImgElement             *pHTMLImgElement    = NULL; 


hrResult = m_spIWebBrowser2->get_Document( &pIDisp);
if (NULL != pIDisp)
{
    hrResult = pIDisp->QueryInterface( __uuidof(IPIEHTMLDocument3), (void**)&pIHTMLDocument);
    if( NULL != pIHTMLDocument)
    {
        IPIEHTMLElement* pElement = NULL;
        CComBSTR pHTMLElement;

        hrResult = pIHTMLDocument->get_documentElement( &pElement);
        if (SUCCEEDED(hrResult)) 
        {                               
            pElement->get_innerHTML(&pHTMLElement.m_str);
            SaveToHTMLFile( pHTMLElement);
        }

        hrResult = pIHTMLDocument->get_images( &pHTMLElementcol);
        if (NULL != pHTMLElementcol)
        {
            CComBSTR  strImage;
            VARIANT vtBase, vtIndex;
            long pHTMLElementCollectionLength = 0;

            VariantInit( &vtBase);
            vtIndex.vt = VT_UINT;

            hrResult = pHTMLElementcol->get_length( &pHTMLElementCollectionLength);
            for (int ilen = 0; ilen < (int)pHTMLElementCollectionLength ; ilen++)
            {           
                vtIndex.lVal = ilen;

                pIDisp = NULL;
                hrResult =  pHTMLElementcol->item( vtBase, vtIndex , &pIDisp);
                if (NULL != pIDisp)
                {
                    hrResult = pIDisp->QueryInterface( __uuidof(IPIEHTMLImgElement), (void**)&pHTMLImgElement);

                    if (NULL != pHTMLImgElement)
                    //CComQIPtr<IPIEHTMLImgElement> imgElement( pIDisp);
                    //imgElement->get_src( &strImage.m_str);    //I get it here :)
                    pHTMLImgElement->get_src( &strImage.m_str);
                }
            }
        }
    }
}

}

Above mentioned code gets the entire web page content in windows mobile devices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文