开发者

htmlcxx compile error

i try to use htmlcxx to parse a webpage. The problem is, the example isnt compileable atm.

tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
    if (it->开发者_JAVA百科tagName() == "A")
    {
        it->parseAttributes();
        std::cout << it->attributes("href");
        std::cout<< std::endl;
    }
}

the problem is it->attributes("href");

the rest is working fine. but with this line, i get

error: no matching function for call to 'htmlcxx::HTML::Node::attributes(const char [5])'

/usr/local/include/htmlcxx/html/Node.h:51: note: candidates are: const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >& htmlcxx::HTML::Node::attributes() const

Does someone have an idea?


I just had a look at the source. The function you want is attribute, not attributes:

// attribute takes a string
std::pair<bool, std::string> attribute(const std::string &attr) const { ... }

// attributes takes nothing
const std::map<std::string, std::string>& attributes() const { return this->mAttributes; }


It looks like the attributes function does not take an attribute name as a parameter, but instead returns all the attributes in a map. You should read the library documentation to confirm this.


I had the same problem. For more info using htmlcxx I found these pages useful (since htmlcxx uses this tree class):

  • http://tree.phi-sci.com/
  • http://tree.phi-sci.com/doxygen/html/classtree.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜