1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

52 lines
1.4 KiB
C++
Raw Normal View History

2017-11-20 16:38:10 +08:00
#include <QCoreApplication>
#include <GumboQueryDocument.h>
#include <GumboQuerySelection.h>
#include <GumboQueryNode.h>
2017-11-22 19:22:53 +08:00
#include "stdlib.h"
#include "stdio.h"
2017-11-20 16:38:10 +08:00
void test_parser()
{
2017-11-22 19:22:53 +08:00
std::string page("<h1><a>wrong link</a><a class=\"special\"\\>some link</a></h1>");
2017-11-20 16:38:10 +08:00
GumboQueryDocument doc;
2017-11-22 19:22:53 +08:00
doc.parse(page.c_str());
2017-11-20 16:38:10 +08:00
2017-11-22 19:22:53 +08:00
GumboQuerySelection c = doc.find("h1 a.special");
GumboQueryNode node = c.nodeAt(0);
printf("Node: %s\n", node.text().c_str());
std::string content = page.substr(node.startPos(), node.endPos() - node.startPos());
printf("Node: %s\n", content.c_str());
2017-11-20 16:38:10 +08:00
}
void test_html()
{
std::string page = "<html><div><span>1\n</span>2\n</div></html>";
GumboQueryDocument doc;
2017-11-22 19:22:53 +08:00
doc.parse(page.c_str());
GumboQueryNode pNode = doc.find("div").nodeAt(0);
std::string content = page.substr(pNode.startPos(), pNode.endPos() - pNode.startPos());
printf("Node: #%s#\n", content.c_str());
2017-11-20 16:38:10 +08:00
}
void test_escape()
{
std::string page = "<html><div><span id=\"that's\">1\n</span>2\n</div></html>";
GumboQueryDocument doc;
2017-11-22 19:22:53 +08:00
doc.parse(page.c_str());
GumboQueryNode pNode = doc.find("span[id=\"that's\"]").nodeAt(0);
std::string content = page.substr(pNode.startPos(), pNode.endPos() - pNode.startPos());
printf("Node: #%s#\n", content.c_str());
2017-11-20 16:38:10 +08:00
}
2017-11-22 19:22:53 +08:00
int main(int argc, char* argv[])
2017-11-20 16:38:10 +08:00
{
2017-11-22 19:22:53 +08:00
QCoreApplication a(argc, argv);
2017-11-20 16:38:10 +08:00
test_parser();
test_html();
test_escape();
return 0;
}