无法获得网页上的文字。

danny5502 2006-12-04 05:48:32
网址:http://news.sina.com.cn/jczs/

为什么用下边的方法无法获得上边网页中的文字?谢谢!
hr = spDoc->get_body(&pElement);
if(SUCCEEDED(hr))
pElement->get_outerText(&bstr1);
...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
guti_milan 2006-12-06
  • 打赏
  • 举报
回复
CString CxxxHtmlView::GetViewSource(IHTMLDocument2* pDoc2)
{
CString strSource;
if (pDoc2)
{
CComPtr<IHTMLElementCollection>pAllElem;
pDoc2->get_all(&pAllElem);
if (pAllElem)
{
IDispatch* pDispTemp = NULL;
CComBSTR strCom;
CComVariant name = 0;
if (SUCCEEDED(pAllElem->item(name,name,&pDispTemp)))
{
CComQIPtr<IHTMLElement> pElem(pDispTemp);
if (pElem)
{
pElem->get_outerHTML(&strCom);

CString strTemp(strCom.m_str);
strSource = strTemp;

}
}
pDispTemp->Release();
}
}
return strSource;
}
当然要确定页面是否加载完毕
然后得到IHTMLDocument2的指针!
lion_wing 2006-12-04
  • 打赏
  • 举报
回复
获得网页源代码:
CString GetSource(IHTMLDocument2* pDoc2)
{
USES_CONVERSION;
CString strReturn("");
CComPtr<IHTMLElementCollection> pElemColl;
HRESULT hr=pDoc2->get_all((IHTMLElementCollection**)&pElemColl);
if(hr==S_OK)
{
CComVariant varIndex=0;
IDispatch *pDisp=NULL;
hr=pElemColl->item(varIndex,varIndex,&pDisp);
if(hr==S_OK)
{
CComPtr<IHTMLElement> pElem;
hr=pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElem);
if(hr==S_OK)
{
CComBSTR strHTML;
hr = pElem->get_outerHTML(&strHTML);
if(hr==S_OK)
{
strReturn=OLE2T(strHTML);
}
}
}
pDisp->Release();
}
return strReturn;
}

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧