崩溃了 求从IHTMLDocument接口遍历HTML中所有元素的代码,该如何解决
崩溃了 求从IHTMLDocument接口遍历HTML中所有元素的代码
网上找的都不好用 ,分不多,能给的全给了
------解决方案--------------------
CComQIPtr<IHTMLElementCollection> pAllCollection;
HRESULT hRes = pDocument->get_all(&spAllCollection);
ASSERT(SUCCEDED(hRes) && (pAllCollection != NULL));
long count=0;
pAllCollection->get_length(&count);
for (int i = 0; i < count; i++)
{
CComPtr<IDispatch> dispElement;
COleVariant elementIndex(count);
HRESULT hResult = pAllCollection->item(index, index, &dispElement);
if(dispElement!=NULL)
{
CComQIPtr<IHTMLElement> pElement(dispElement);
网上找的都不好用 ,分不多,能给的全给了
------解决方案--------------------
CComQIPtr<IHTMLElementCollection> pAllCollection;
HRESULT hRes = pDocument->get_all(&spAllCollection);
ASSERT(SUCCEDED(hRes) && (pAllCollection != NULL));
long count=0;
pAllCollection->get_length(&count);
for (int i = 0; i < count; i++)
{
CComPtr<IDispatch> dispElement;
COleVariant elementIndex(count);
HRESULT hResult = pAllCollection->item(index, index, &dispElement);
if(dispElement!=NULL)
{
CComQIPtr<IHTMLElement> pElement(dispElement);