比如 html tidy,和htmlcxx库等。可以用的很多,不再赘述,贴上写htmlcxx的应用例子:
解析特定的文本段落
std::string strHtml = "<font size=\"-1\" color=#808080>dddddd 加入了对话</font>";
htmlcxx::HTML::ParserDom parser ;
tree<htmlcxx::HTML::Node> dom = parser.parseTree(strHtml) ;
tree<htmlcxx::HTML::Node>::iterator it = dom.begin();
tree<htmlcxx::HTML::Node>::iterator end = dom.end();
for ( ; it != end ; ++ it)
{
std::string strText;
if (it->isComment())
continue ;
if (it->isTag())
{
it->parseAttributes();
if(it->tagName() == "font")
{
std::pair<bool, std::string> Size = it->attribute("size");
std::pair<bool, std::string> Color = it->attribute("color");
std::string strSize = Size.second;
std::string strColor = Color.second;
}
}
}