熟悉使用JS操作网页后,就懒得想C++怎么操作了。不过最近工作需要,在CBC下操作网页内容的小工具,别有一凡风味。贴框架代码如下:
1。得到网页document:
IHTMLDocument3 *pDocument;
hr = CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument3,(void**)&pDocument) ;
if( !SUCCEEDED(hr) )
{
//ShowMessage("hehe") ;
//return " ";
}
2.得到表格对象数组:
IHTMLElementCollection *ecElements;
hr = pDocument->getElementsByTagName(WideString("table"),&ecElements);
if( !SUCCEEDED(hr) )
{
Application->MessageBoxA("获取元素失败!", "提示", MB_OK) ;
}
3.得到具体一个table对象
IHTMLTable *ihtmlTable;
vtIndex.lVal = i;
vtName.lVal = i;
ecElements->item(vtName, vtIndex,&pDisch);
///get table
pDisch->QueryInterface(IID_IHTMLTable, (void **) &ihtmlTable);
4。行对象
htmlTable->get_rows(&ecRows);
ecRows->item(vtName, vtIndex,&pDisch);
if (pDisch != NULL)
{
pDisch->QueryInterface(IID_IHTMLTableRow, (void **)&htRow);
writeRowtoEdit(htRow);
iOrder++;
}
至此为止,这样就基本说明了在CBC中处理网页内容的大体框架。END!