void CMGDlg::OnBnClickedButtonGetwebdata(void)
{
CString allPointData;
IDispatch *pDisp = webbrowser1.get_Document();
IHTMLDocument2* pDocument;
IHTMLElementCollection* pCollection;
pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);
HRESULT hr;
hr = pDocument->get_all(&pCollection);
if( hr == S_OK )
{
long celem;
hr = pCollection->get_length(&celem); //得到所有节点的个数用以遍历
if( hr == S_OK )
{
VARIANT varIndex, var;
for ( int i = 0; i < celem; i++ )
{
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VariantInit(&var);
hr = pCollection->item(varIndex,var,&pDisp);
if ( hr == S_OK )
{
IHTMLElement *pElement;
hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement);
if ( hr == S_OK )
{
CString pointData,id;
BSTR bs= SysAllocString(L"");
//pElement->get_id(&bs);
//pElement->get_className(&bs);
pElement->get_tagName(&bs);
id = CString(bs);
if ( id == _T("TABLE") )
{
//IHTMLInputElement* input;
//hr = pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&input);
//input->get_value(&bs); //将id为LanLonPoints中的value值赋给bs
//pointData = CString(bs);
//allPointData = pointData;
VARIANT index;
VARIANT varID;
V_VT(&index) = VT_I4;
V_I4(&index) = 1;
CString strInfo;
IHTMLTable * pTable; // 获得表格元素接口
hr = pDisp->QueryInterface(IID_IHTMLTable,(void **)&pTable );
if ( (hr == S_OK) && (pTable != NULL) )
{
IHTMLElementCollection* pColl2 = NULL;
pTable->get_rows(&pColl2); // 获取表格行
IDispatch* pDisp2;
V_I4(&index) = 1;
hr = pColl2->item( index,index, &pDisp2 ); // 获取第2行位置
if ( (hr == S_OK) && (pDisp2 != NULL) )
{
IHTMLTableRow* pRow; // 获取行元素接口
hr = pDisp2->QueryInterface(IID_IHTMLTableRow,(void **)&pRow);
if( (hr == S_OK) && (pRow != NULL) )
{
IHTMLElementCollection* pColl3 = NULL;
pRow->get_cells(&pColl3); // 获取格子元素
IDispatch* pDisp3;
V_I4(&index) = 1;
hr = pColl3->item( index,index, &pDisp3 ); // 获取第2行第2格元素
if ( (hr == S_OK) && (pDisp2 != NULL) )
{
IHTMLElement* pElem; // 获取元素接口
hr = pDisp3->QueryInterface(IID_IHTMLElement,(void **)&pElem);
if( hr == S_OK )
{
BSTR bstr = SysAllocString(L"");
pElem->get_innerText(&bstr); // 获取该表格元素的文本信息
strInfo =bstr;
//MessageBoxExA(NULL,strInfo,NULL,NULL,NULL);
pElem->Release();
}
pDisp3->Release();
}
pRow->Release();
}
pDisp2->Release();
}
pTable->Release();
}
pDisp->Release();
}
}
}
}
}
}
}
{
CString allPointData;
IDispatch *pDisp = webbrowser1.get_Document();
IHTMLDocument2* pDocument;
IHTMLElementCollection* pCollection;
pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);
HRESULT hr;
hr = pDocument->get_all(&pCollection);
if( hr == S_OK )
{
long celem;
hr = pCollection->get_length(&celem); //得到所有节点的个数用以遍历
if( hr == S_OK )
{
VARIANT varIndex, var;
for ( int i = 0; i < celem; i++ )
{
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VariantInit(&var);
hr = pCollection->item(varIndex,var,&pDisp);
if ( hr == S_OK )
{
IHTMLElement *pElement;
hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement);
if ( hr == S_OK )
{
CString pointData,id;
BSTR bs= SysAllocString(L"");
//pElement->get_id(&bs);
//pElement->get_className(&bs);
pElement->get_tagName(&bs);
id = CString(bs);
if ( id == _T("TABLE") )
{
//IHTMLInputElement* input;
//hr = pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&input);
//input->get_value(&bs); //将id为LanLonPoints中的value值赋给bs
//pointData = CString(bs);
//allPointData = pointData;
VARIANT index;
VARIANT varID;
V_VT(&index) = VT_I4;
V_I4(&index) = 1;
CString strInfo;
IHTMLTable * pTable; // 获得表格元素接口
hr = pDisp->QueryInterface(IID_IHTMLTable,(void **)&pTable );
if ( (hr == S_OK) && (pTable != NULL) )
{
IHTMLElementCollection* pColl2 = NULL;
pTable->get_rows(&pColl2); // 获取表格行
IDispatch* pDisp2;
V_I4(&index) = 1;
hr = pColl2->item( index,index, &pDisp2 ); // 获取第2行位置
if ( (hr == S_OK) && (pDisp2 != NULL) )
{
IHTMLTableRow* pRow; // 获取行元素接口
hr = pDisp2->QueryInterface(IID_IHTMLTableRow,(void **)&pRow);
if( (hr == S_OK) && (pRow != NULL) )
{
IHTMLElementCollection* pColl3 = NULL;
pRow->get_cells(&pColl3); // 获取格子元素
IDispatch* pDisp3;
V_I4(&index) = 1;
hr = pColl3->item( index,index, &pDisp3 ); // 获取第2行第2格元素
if ( (hr == S_OK) && (pDisp2 != NULL) )
{
IHTMLElement* pElem; // 获取元素接口
hr = pDisp3->QueryInterface(IID_IHTMLElement,(void **)&pElem);
if( hr == S_OK )
{
BSTR bstr = SysAllocString(L"");
pElem->get_innerText(&bstr); // 获取该表格元素的文本信息
strInfo =bstr;
//MessageBoxExA(NULL,strInfo,NULL,NULL,NULL);
pElem->Release();
}
pDisp3->Release();
}
pRow->Release();
}
pDisp2->Release();
}
pTable->Release();
}
pDisp->Release();
}
}
}
}
}
}
}