CComPtr< IDispatch > pDisp=NULL;
CComQIPtr <IHTMLElementCollection> pColl;
CComQIPtr<IHTMLTable> Table;
CComQIPtr<IHTMLTableRow> Row;
CComQIPtr <IHTMLElement> pEl;
CComQIPtr <IHTMLElementCollection> pIRows;
CComQIPtr <IHTMLElementCollection> pICell;
CComQIPtr<IHTMLTableCell> pCell;
IHTMLDocument2* pDoc2;
CString str;
BSTR bsStr;
pDoc2->get_all(&pColl);
pColl->tags(COleVariant("table"),&pDisp);
if (pDisp==NULL) return;
pColl.Release();
pColl=pDisp;
pDisp.Release();
long lCnt=0;
pColl->get_length(&lCnt);//得到网页里所有的表格
for (int n=0;n<lCnt;n++)
{
CComVariant cvt;
cvt=(long)n;
pColl->item(COleVariant((long)n),cvt,&pDisp);
Table=pDisp;
pDisp.Release();
long lRow=0;
Table->get_rows(&pIRows);
pIRows->get_length(&lRow);//得到表格里所有的行
for (long j=0;j<lRow;j++)
{
pIRows->item(COleVariant((long)j),COleVariant((long)0),&pDisp);
Row=pDisp;
pDisp.Release();
Row->get_cells(&pICell);
long lCell=0;
pICell->get_length(&lCell);//遍历每一行里面的单元格
for (long k=0;k<lCell;k++)
{
pICell->item(COleVariant((long)k),COleVariant((long)0),&pDisp);
pEl=pDisp;
pCell=pDisp;
pEl->get_outerText(&bsStr);
str=bsStr;//得到单元格里面的内容
pEl.Release();
pDisp.Release();
}
Row.Release();
pICell.Release();
}
pIRows.Release();
Table.Release();
}
pColl.Release();
CComQIPtr <IHTMLElementCollection> pColl;
CComQIPtr<IHTMLTable> Table;
CComQIPtr<IHTMLTableRow> Row;
CComQIPtr <IHTMLElement> pEl;
CComQIPtr <IHTMLElementCollection> pIRows;
CComQIPtr <IHTMLElementCollection> pICell;
CComQIPtr<IHTMLTableCell> pCell;
IHTMLDocument2* pDoc2;
CString str;
BSTR bsStr;
pDoc2->get_all(&pColl);
pColl->tags(COleVariant("table"),&pDisp);
if (pDisp==NULL) return;
pColl.Release();
pColl=pDisp;
pDisp.Release();
long lCnt=0;
pColl->get_length(&lCnt);//得到网页里所有的表格
for (int n=0;n<lCnt;n++)
{
CComVariant cvt;
cvt=(long)n;
pColl->item(COleVariant((long)n),cvt,&pDisp);
Table=pDisp;
pDisp.Release();
long lRow=0;
Table->get_rows(&pIRows);
pIRows->get_length(&lRow);//得到表格里所有的行
for (long j=0;j<lRow;j++)
{
pIRows->item(COleVariant((long)j),COleVariant((long)0),&pDisp);
Row=pDisp;
pDisp.Release();
Row->get_cells(&pICell);
long lCell=0;
pICell->get_length(&lCell);//遍历每一行里面的单元格
for (long k=0;k<lCell;k++)
{
pICell->item(COleVariant((long)k),COleVariant((long)0),&pDisp);
pEl=pDisp;
pCell=pDisp;
pEl->get_outerText(&bsStr);
str=bsStr;//得到单元格里面的内容
pEl.Release();
pDisp.Release();
}
Row.Release();
pICell.Release();
}
pIRows.Release();
Table.Release();
}
pColl.Release();