谁有提取HTML中的文本的代码? 我搜索了好久,就是没有找到!谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BOOL StripTags(LPTSTR pszBuffer,LPTSTR pszTitle){ static BOOL bInTag = FALSE; LPTSTR pszSource=NULL; pszSource = strstr(pszBuffer,"<BODY");//pszBuffer; if(pszSource==NULL) pszSource = strstr(pszBuffer,"<body");//pszBuffer; if(pszSource==NULL) return FALSE; LPTSTR title_begin=strstr(pszBuffer,"<TITLE>"); if(title_begin==NULL) title_begin=strstr(pszBuffer,"<title>"); if(title_begin==NULL||title_begin>pszSource) return FALSE; LPTSTR title_end=strstr(title_begin,"</"); strncpy(pszTitle,title_begin+7,title_end-title_begin-7); pszTitle[title_end-title_begin-7]=0; LPTSTR pszDest = pszBuffer; while (*pszSource != '\0') { if (bInTag) { if (*pszSource == '>') bInTag = FALSE; pszSource++; } else { if (*pszSource == '<') bInTag = TRUE; else { *pszDest = *pszSource; pszDest++; } pszSource++; } } *pszDest = '\0'; return TRUE;} 我做了一个 文本文件<==>HTML文件 互相转换的程序,留下email地址,我将VC源码发给你。 wmrwinhap(边城浪子):[email protected]thank you! 请给我一份好吗?我一直在寻找,就是没找到。[email protected]十分谢谢 到w3c.org上下载libHTML,里面有关于html parse的方法,基本上是创建一个有限状态机,来分析html的tag和attribute,见SGML_Write函数 如果是用 MFC 的 HtmlView 就简单了,几行代码就可以搞定#include <Mshtml.h>#include <atlbase.h>CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument2> pDoc(GetHtmlDocument());CComQIPtr<IHTMLElement> pBody;pDoc->get_body(&pBody);CComBSTR bstr;pBody->get_innerText(&bstr);CString strText(bstr);MessageBox(strText); 给我一份[email protected] See the links below: http://www.codeproject.com/cpp/stlxmlparser.asphttp://www.codeproject.com/soap/paramio.asp 如何将AUTO CAD文件 转换成bmp文件 求教VC中MFC errorC2664 问题 利用CSocket传输大流量数据的问题 付费:打印纸张的统计,打印内容的监控 的源代码(VC的) 100分求解DLL调用问题!!急!!!!!!!!!! 如何在套接字中使用xml? 映射模式中的比例问题 关于进程启动的问题 怎样编程让终端服务器重启? 请问什么地方有visual c++技术内幕的电子版下载 一个小问题!请教。 Invaliddate()和RedrawWindow()有何区别?
{
static BOOL bInTag = FALSE;
LPTSTR pszSource=NULL;
pszSource = strstr(pszBuffer,"<BODY");//pszBuffer;
if(pszSource==NULL)
pszSource = strstr(pszBuffer,"<body");//pszBuffer;
if(pszSource==NULL)
return FALSE;
LPTSTR title_begin=strstr(pszBuffer,"<TITLE>");
if(title_begin==NULL)
title_begin=strstr(pszBuffer,"<title>");
if(title_begin==NULL||title_begin>pszSource)
return FALSE;
LPTSTR title_end=strstr(title_begin,"</");
strncpy(pszTitle,title_begin+7,title_end-title_begin-7);
pszTitle[title_end-title_begin-7]=0;
LPTSTR pszDest = pszBuffer; while (*pszSource != '\0')
{
if (bInTag)
{
if (*pszSource == '>')
bInTag = FALSE;
pszSource++;
}
else
{
if (*pszSource == '<')
bInTag = TRUE;
else
{
*pszDest = *pszSource;
pszDest++;
}
pszSource++;
}
}
*pszDest = '\0';
return TRUE;
}
[email protected]
thank you!
我一直在寻找,
就是没找到。
[email protected]十分谢谢
#include <Mshtml.h>
#include <atlbase.h>CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument2> pDoc(GetHtmlDocument());
CComQIPtr<IHTMLElement> pBody;
pDoc->get_body(&pBody);
CComBSTR bstr;
pBody->get_innerText(&bstr);
CString strText(bstr);
MessageBox(strText);
[email protected]
http://www.codeproject.com/soap/paramio.asp