lunch-rest/htmlparser.hpp
2020-09-15 00:55:03 +02:00

28 lines
639 B
C++

#ifndef HTML_PARSER_H
#define HTML_PARSER_H
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
class HtmlParser {
public:
HtmlParser() = delete;
HtmlParser(const std::string &html) {
doc = htmlReadDoc((xmlChar*)html.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
auto r = xmlDocGetRootElement(doc);
root.reset(new xmlpp::Element(r));
}
~HtmlParser() {
xmlFreeDoc(doc);
}
xmlpp::Element &getRoot() {
return *root;
}
private:
xmlDoc *doc;
std::unique_ptr<xmlpp::Element> root;
};
#endif