VC遍历表格元素

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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值