Html 在Windows mobile 6.0中获取网页文档
在internet上搜索lot后,我们发现以下代码仅用于将网页的主体部分加载到web浏览器控件Html 在Windows mobile 6.0中获取网页文档,html,internet-explorer,windows-mobile,webbrowser-control,smartphone,Html,Internet Explorer,Windows Mobile,Webbrowser Control,Smartphone,在internet上搜索lot后,我们发现以下代码仅用于将网页的主体部分加载到web浏览器控件 IPIEHTMLDocument2 *pHTMLDocument; IPIEHTMLElement* pBodyElement; CComPtr<IDispatch> spDispDoc; HRESULT res = m_spWebBrowser2->get_Document(&spDispDoc); if(SUCCEEDED(res)) { spDisp
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);
}
}
IPIEHTMLDocument2*pHTMLDocument;
IPIEHTMLElement*pBodyElement;
CComPtr spDispDoc;
HRESULT res=m_spWebBrowser2->获取文档(&spDispDoc);
如果(成功(res))
{
spDispDoc->QueryInterface(u_uidof(IPIEHTMLDocument2),(void**)和pHTMLDocument);
WCHAR-szText[256];
DISPID id;
奥尔卡尔·法尔*szTemp;
//存储“body”
szTemp=szText;
StringCchPrintf(szText,256,L“主体”,id);
//抓住尸体
pHTMLDocument->GetIDsOfNames(IID\u NULL,&szTemp,1,LOCALE\u USER\u DEFAULT,&id);
变异结果;
varResult.vt=vt_调度;
变量FAR*pVarResult=&varResult;
DISPPARAMS dispparamsNoArgs={NULL,NULL,0,0};
pHTMLDocument->Invoke(id、IID\u NULL、LOCALE\u USER\u DEFAULT、DISPATCH\u PROPERTYGET和dispparamsNoArgs、pVarResult、NULL、NULL);
BSTR体值;
if(NULL!=pVarResult->pdispVal)
{
pVarResult->pdispVal->QueryInterface(IID_IPIEHTMLElement,(void**)和pBodyElement);
pBodyElement->get_innerHTML(&bodyValue);
}
}
但是现在我们如何从加载的网页中获取剩余的头部和其他标记文档文本,
甚至我们也尝试过将“head”字符串传递给GetIDsOfNames()方法,但它传递的是fail值,因此我们感到震惊。
请向我们提供在windows mobile 6.0中访问/提取整个网页内容的方法
谢谢,
Ramanand Bhat.void CBrowserWindow::ExtractWebPageDoc()
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);
}
}
}
}
}
{
HRESULT hrResult=E_FAIL;
IDispatch*pIDisp=NULL;
IPIEHTMLDocument3*pIHTMLDocument=NULL;
IPIEHTMLElementCollection*pHTMLElementcol=NULL;
IPIEHTMLImgElement*pHTMLImgElement=NULL;
hrResult=m_spIWebBrowser2->get_文档(&pIDisp);
如果(NULL!=pIDisp)
{
hrResult=pIDisp->QueryInterface(u_uidof(IPIEHTMLDocument3),(void**)和pIHTMLDocument);
if(NULL!=pIHTMLDocument)
{
IPIEHTMLElement*pElement=NULL;
CComBSTR phtmlement;
hrResult=pIHTMLDocument->get_documentElement(&pElement);
如果(成功(hrResult))
{
pElement->get_innerHTML(&phtmlement.m_str);
SaveToHTMLFile(pHTMLElement);
}
hrResult=pIHTMLDocument->get_images(&pHTMLElementcol);
if(NULL!=pHTMLElementcol)
{
CComBSTR擦伤;
变量vtBase、vtIndex;
长pHTMLElementCollectionLength=0;
VariantInit(&vtBase);
vtIndex.vt=vt_UINT;
hrResult=pHTMLElementcol->get_length(&pHTMLElementCollectionLength);
对于(int-ilen=0;ilen<(int)pHTMLElementCollectionLength;ilen++)
{
vtIndex.lVal=ilen;
pIDisp=NULL;
hrResult=pHTMLElementcol->item(vtBase、vtinex和pIDisp);
如果(NULL!=pIDisp)
{
hrResult=pIDisp->QueryInterface(uu uuidof(IPIEHTMLImgElement),(void**)和phtmmlimgelement);
if(NULL!=pHTMLImgElement)
//CComQIPtr imgElement(pIDisp);
//imgElement->get_src(&strImage.m_str);//我在这里得到它:)
pHTMLImgElement->get_src(&strImage.m_str);
}
}
}
}
}
}
上述代码获取windows mobile设备中的整个网页内容