IHTMLElementCollection cannot read all html elements

  • Thread starter Thread starter mesajflaviu
  • Start date Start date
M

mesajflaviu

Guest
I have a SDI app, with CView based on CHtmlView. But I cannot read all html elements through IHTMLElementCollection, on this site:

void CTestAutoView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();

SetSilent(TRUE);
Navigate2(_T("Piese Auto Online - Comanda Piese Auto | Autoatu.ro"), NULL, NULL);
}



and here is the code where I am trying to read all elements:

void CTestAutoView::OnNavigateComplete2(LPCTSTR strURL)
{
// TODO: Add your specialized code here and/or call the base class

CHtmlView::OnNavigateComplete2(strURL);

IHTMLDocument2* pHtmlDoc = NULL;

// Retrieve the document object.
IDispatch* pHtmlDocDispatch = GetHtmlDocument();
if (pHtmlDocDispatch != NULL)
{
HRESULT hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pHtmlDoc);
if(SUCCEEDED(hr) && NULL != pHtmlDoc)
{
IHTMLElementCollection* pColl = NULL;
hr = pHtmlDoc->get_all(&pColl);
if(SUCCEEDED(hr) && NULL != pColl)
{
long nLength = 0;
pColl->get_length(&nLength);

for(int i = 0;i < nLength;++i)
{
COleVariant vIdx((long)i, VT_I4);

IDispatch* pElemDispatch = NULL;
IHTMLElement* pElem = NULL;

hr = pColl->item(vIdx, vIdx, &pElemDispatch);

if(SUCCEEDED(hr) && NULL != pElemDispatch)
{
hr = pElemDispatch->QueryInterface(IID_IHTMLElement, (void**)&pElem);

if(SUCCEEDED(hr) && NULL != pElem)
{
BSTR bstrTagName;
CString sTempTagName;
if (! FAILED(pElem->get_tagName(&bstrTagName)))
{
sTempTagName = bstrTagName;
SysFreeString(bstrTagName);
}
TRACE(">>>>>>>>%S\n", sTempTagName);
}
}
}
}
}
}
}


the only tags that is read it by the code from above is:

>>>>>>>>!
>>>>>>>>HTML
>>>>>>>>HEAD
>>>>>>>>TITLE
>>>>>>>>META
>>>>>>>>META
>>>>>>>>META
>>>>>>>>META
>>>>>>>>META
>>>>>>>>SCRIPT

which is not normal, the site has a lot of html tags. Why IHTMLElementCollection cannot read all tags ? I attach here a sample project which reveal the issue (VS2010):

TestAuto VS2010 project

Continue reading...
 
Back
Top