Code Monkey home page Code Monkey logo

htmlparser's Introduction

htmlparser

a simple c++ html parser

Intro

Chinese Introduction

https://xilixili.net/2017/03/16/htmlparser/

  • support html and xhtml document
  • support getElementById(ClassName/TagName)
  • support simple XPath select interface

Usage

Basic usage please see demo test.cpp.

The compiler must support at least tr1 both Win and GNU/Linux for smart_ptr & unordered_set.

Any c++11 compiler was supported. others may works.

htmlparser's People

Contributors

rangerlee avatar testmigrator avatar

Stargazers

nk125 avatar otero avatar Cubevlmu avatar  avatar  avatar  avatar  avatar ChenPi11 avatar Flaviu_ avatar 牛牛 avatar 养乐多 avatar maxbad avatar  avatar  avatar  avatar  avatar  avatar Kevinlinpr avatar Hao Yujie avatar

Watchers

 avatar Hoa Thiên Vũ avatar

htmlparser's Issues

halo

同样是c++做爬虫,解析html

我用的tidy,将html格式化到xhtml
然后就可以xml解析了

Text method fails to handle invalid start tags, resulting in incorrect output.

The text() method is not handling invalid start tags correctly, resulting in incorrect text output

TEST(test, handlesInvalidStartTags) {
    std::string html("<html><div>Hello < There <&amp;></div></html>");
    HtmlParser parser;
    shared_ptr<HtmlDocument> doc = parser.Parse(html);
    std::vector<shared_ptr<HtmlElement>> els = doc->SelectElement("//div");
    
    ASSERT_EQ(1, els.size());

    // ASSERT_EQ("Hello < There <&>", els[0]->text());
    ASSERT_EQ("Hello ", els[0]->text());
}

Script tag not handled properly when escaped

The expected value of els[0]->GetValue() is not returned, when handling escaped script, which leads to incorrect parsing.

TEST(test, handlesEscapedScript) {
    HtmlParser parser;
    shared_ptr<HtmlDocument> doc = parser.Parse("<html><script><!-- one <script>Blah</script> --></script></html>");
    vector<shared_ptr<HtmlElement>> els = doc->SelectElement("//script");
    ASSERT_EQ(1, els.size());
    // <!-- one <script>Blah
    // ASSERT_EQ("<!-- one <script>Blah</script> -->", els[0]->GetValue());
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.