We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
问题场景:
给定这样一个page:
std::string page = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>Title</title></head><body><img src=\"file:///d:/test.png\" /><img src=\"file:///d:/test2.png\" /><img src=\"http://blablabla.png\" /><div><div><img src=\"http://asdfasfdsaf.com/asdf.png\" alt=\"alternative text\"/><img src=\"file:///d:/test3.png\" /></div><div1><div2><div3><img id=\"imgId2\" src=\"http://www.taobao.com\" /><pre><img src=\"file:///foo\" id=\"bar\" id=\"notexists\"/></pre></div3></div2></div1></div></body></html>";
在其中查找所有tag为img的node
auto nodes = doc.find("IMG");
然后取出这些node的 startPos 和 endPos , 发现它们 startPos 是指向标签末尾的,endPos指向 标签开始,是不是这两个函数的实现搞反了?
The text was updated successfully, but these errors were encountered:
哥们儿,qq多少
Sorry, something went wrong.
确实是反过来了。
测试代码如下:
void test_image_tag() { std::string page = "<img />"; CDocument doc; doc.parse(page.c_str()); CNode node = doc.find("IMG").nodeAt(0); std::cout << "startPos:" << node.startPos() <<" endPos:"<< node.endPos() << std::endl; std::cout << "startPosOuter:" << node.startPosOuter() <<" endPosOuter:"<< node.endPosOuter() << std::endl; }
输出如下:
startPos:7 endPos:0 startPosOuter:0 endPosOuter:0
另一个测试代码
void test_div_tag() { std::string page = "<div></div>"; CDocument doc; doc.parse(page.c_str()); CNode node = doc.find("div").nodeAt(0); std::cout << "startPos:" << node.startPos() <<" endPos:"<< node.endPos() << std::endl; std::cout << "startPosOuter:" << node.startPosOuter() <<" endPosOuter:"<< node.endPosOuter() << std::endl; }
startPos:5 endPos:5 startPosOuter:0 endPosOuter:11
测试 input 标签和 img 标签结果类似。
input
img
@lazytiger
No branches or pull requests
问题场景:
给定这样一个page:
在其中查找所有tag为img的node
然后取出这些node的 startPos 和 endPos ,
发现它们 startPos 是指向标签末尾的,endPos指向 标签开始,是不是这两个函数的实现搞反了?
The text was updated successfully, but these errors were encountered: