HTML解析 C/C++ (散分),该如何处理

HTML解析 C/C++ (散分)
1:看着好多人在找这方面的资料,就发一版今年国庆节写的类,可以解析99%的HTML页面。由于申请过多的内存和过多的内存拷贝,效率嘛肯定不太好。注释少了些(可以说没有),代码呢也糙了些(已经在重构了)。各位将就着看吧。

2:里面用到几个WINDOWS API函数,如果想在其它系统使用,请自行更换成标准C或标准C++函数。

3:两个类:一个基础类(CHtmlHelper,解析HTML文件,生成元件链表),一个功能类(CHtmlAnalyzer,转换页面编码为程序所使的编码,再调用CHtmlHelper进行解析 )。

----顺带打一下广告:参加工作快5年了,想换一份工作,C/C++方面的。邮箱:hmm7e_z@126.com。



class CHtmlHelper
{
public:
//
static LPCTSTR SkipSpace(LPCTSTR lpszString);
static LPCTSTR SkipLetter(LPCTSTR lpszString,TCHAR cbLetter);
static LPCTSTR ArriveLetter(LPCTSTR lpszString,TCHAR cbLetter);
static UINT CalculateStringLen(LPCTSTR lpszString,TCHAR* lpszEnd);
static UINT CalculateRangeLen(LPCTSTR lpszString,LPCTSTR lpszBegin,LPCTSTR lpszEnd);
static UINT CalculateTagStringLen(LPCTSTR lpszString,TCHAR cbBegin,TCHAR cbEnd);
static UINT CalculateScriptStringLen(LPCTSTR lpszString,TCHAR cbEnd);
static  void TrimString(LPCTSTR lpszString,LPCTSTR lpszClean);
protected:
struct tagHtmlTagAttribute
{
LPTSTR s_pszKey;
LPTSTR s_pszValue;
struct tagHtmlTagAttribute * s_pstNext;
};
struct tagHtmlNode
{
LPTSTR s_pszTag;
LPTSTR s_pszContent;
tagHtmlTagAttribute * s_pstTagAttribute;
struct tagHtmlNode * s_pstNext;
};
public:
CHtmlHelper(void);
virtual ~CHtmlHelper(void);
protected:
//
tagHtmlNode * AllocHtmlNode(UINT nTagLen,UINT nContentLen);
void FreeHtmlNode(tagHtmlNode * lpstNode);
void LinkHtmlNode(tagHtmlNode * lpstNode);
void CleanupHtmlNode();
//
tagHtmlTagAttribute * AllocHtmlTagAttribute(UINT nKeyLen,UINT nValueLen);
void FreeHtmlTagAttribute(tagHtmlTagAttribute * lpstTagAttribute);
void AttachHtmlTagAttribute(tagHtmlNode * lpstNode,tagHtmlTagAttribute * lpstTagAttribute);
void CleanupHtmlTagAttribute(tagHtmlNode * lpstNode);
public:
enum {CHARSET_UTF8,CHARSET_UNICODE,CHARSET_MULTIBYTE}TextCharset;
public:
//
void AutoTakeSnapshot(PBYTE lpszString,UINT nStringLen);
void TakeSnapshot(PBYTE lpszString,UINT nStringLen,UINT nFromCharset );
void DeleteSnapshot();
//
virtual void Parse();
virtual void Parse2();
protected:
//
void SplitTagAttribute(tagHtmlNode * lpstNode);

protected:
//
LPTSTR  m_pszSnapshotBuffer;
UINT m_nSnapshotBufferLen;
UINT m_nSnapshotStringLen;
//
tagHtmlNode * m_pstHead;
tagHtmlNode * m_pstPrev;

};



------解决方案--------------------
技术贴外加求职贴 = 值得肯定
HTML解析 C/C++ (散分),该如何处理
------解决方案--------------------
非常难得!
------解决方案--------------------
学习了
------解决方案--------------------
学习并接分.
------解决方案--------------------
我也来学习下
------解决方案--------------------
HTML解析 C/C++ (散分),该如何处理
------解决方案--------------------
HTML解析 C/C++ (散分),该如何处理
------解决方案--------------------
这个绝对是好东西啊!
------解决方案--------------------
好吧,新手知道这里还可以求职
学习了~
------解决方案--------------------
观摩技术性思想
------解决方案--------------------
好东西
------解决方案--------------------
编程没学好。
------解决方案--------------------
HTML解析 C/C++ (散分),该如何处理
------解决方案--------------------
纠结、、、、、、
------解决方案--------------------
犀利,Mark一下
------解决方案--------------------
收藏,汗,我也在写简单解析类
------解决方案--------------------

 static void Main(string[] args)
        {
            EndpointAddress endpoint = new EndpointAddress("http://wcf.com/wcf5calculator.svc");
            WSHttpBinding httpBinding = new WSHttpBinding();
            ChannelFactory<ICalculator> calcultor = new ChannelFactory<ICalculator>(httpBinding, endpoint);
            ICalculator channel = calcultor.CreateChannel();
            Console.WriteLine(channel.Add(27,58));
            Console.ReadKey();
        }

------解决方案--------------------
很好。。。mark
------解决方案--------------------
为什么不考虑用一些工具来提高效率,譬如正则表达式,可以非常有效的降低词法分析的复杂程度!
还有那个输出接口,能不能做好一点?!譬如生成DOM树。
------解决方案--------------------
HTML解析 C/C++ (散分),该如何处理