浏览器插件获取网页内容

void GetHtmlContent()
{
	//m_Explorer
	HRESULT hr;
	LPDISPATCH pDisp;
	IHTMLDocument2*    phd;//IHtmlDocument2接口指针
	IHTMLElement* pBody;//网页中的元素
	pDisp = m_Explorer.get_Document();
	hr = pDisp->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&phd);
	pDisp->Release();
	if (SUCCEEDED(hr))
	{
		BSTR bstrText;
		hr = phd->get_body(&pBody); //BODY
		if (SUCCEEDED(hr))
		{
			hr = pBody->get_innerText(&bstrText); 
			if (SUCCEEDED(hr))
			{
				//PrintBSTR(bstrText);  // 处理得到的文本
				char* lpszText2 = _com_util::ConvertBSTRToString(bstrText);  
				g_Log.print(LogLevel_Info,"[info] GetHtmlContent:%s.\n",lpszText2);
				SysFreeString(bstrText);
				//AfxMessageBox("获取成功");
			}
		}
		SysFreeString(bstrText);
	}
	phd->Release(); 
	pBody->Release();


 
}

你可能感兴趣的:(VC++)