当前位置: 首页 > 工具软件 > htmlcxx > 使用案例 >

htmlcxx取指定字段实例

沃念
2023-12-01

#include <string>

#include <iostream>

#include <sstream>

#include <htmlcxx/html/ParserDom.h>

#include <stdlib.h>

#include <stdio.h>

#include <unistd.h>

 

using namespace std;

using namespace htmlcxx;

 

int main()

{

  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;

      }

    }

  }

  return 0;

}

 

转载于:https://www.cnblogs.com/dancheblog/p/4422533.html

 类似资料: