0

我替换了html="中文网页内容",编译不出来。它失败了,我想知道当我输入任何 id、class、tag 名称或名称时如何成功编译并获取内容。

#include <htmlcxx/html/ParserDom.h>
...
using namespace std;
using namespace htmlcxx;

//Parse some html code

string html = "<html><body>hey</body></html>";
HTML::ParserDom parser;
tree<HTML::Node> dom = parser.parseTree(html);

//Print whole DOM tree

cout << dom << endl;

//Dump all links in the tree

tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
 if (strcasecmp(it->tagName().c_str(), "A") == 0)
 {
   it->parseAttributes();
   cout << it->attribute("href").second << endl;
 }
}

//Dump all text of the document
it = dom.begin();
end = dom.end();
for (; it != end; ++it)
{
 if ((!it->isTag()) && (!it->isComment()))
 {
  cout << it->text();
 }
}
cout << endl;
4

0 回答 0