Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Gumbo Parser
Forum Updated to NodeBB v4.3 + New Features

Gumbo Parser

Scheduled Pinned Locked Moved Solved General and Desktop
c++gumbo
4 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EvgeE Offline
    EvgeE Offline
    Evge
    wrote on last edited by
    #1

    Hi, I try the lib Gumbo Parser and
    had such difficulty.
    Ubuntu Qt 5.4.2
    my code:

    QString html("<html>"
                     "<head>"
                     " <title>Title</title>"
                     "</head>"
                     "<body>"
                     "<p>some string</p>"
                     "<div class = \'id\'><p>some dive ID</p></div>"
                     "</body>"
                     "</html>");
        GumboOutput* out = gumbo_parse(html.toUtf8().constData());
        GumboNode* node = out->root;
        qDebug() << node->v.element.children.length;
    

    Answer: 2 -- it's good and lib is working.
    but

    GumboVector* vec = &node->v.element.children;
        for (int x = 0; x < vec->length; x++){
           GumboNode* nodeX = &vec->data[x];
            qDebug() << nodeX->v.text.text;
        }
    

    Answer: cannot convert 'void**' to 'GumboNode* {aka GumboInternalNode*}' in initialization
    GumboNode* nodeX = &vec->data[x];
    ^
    Please tell me how to convert. Thanks

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by JohanSolo
      #2

      @Evge said:

      Please tell me how to convert. Thanks

      Well, this is not exactly related to Qt... You should try to ask the gumbo developpers.

      Edit:

      I read a bit fast your question, your problem is purely C++. Apparently vec->data[x] already gives you back a pointer, of which you are taking the address.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      EvgeE 1 Reply Last reply
      0
      • JohanSoloJ JohanSolo

        @Evge said:

        Please tell me how to convert. Thanks

        Well, this is not exactly related to Qt... You should try to ask the gumbo developpers.

        Edit:

        I read a bit fast your question, your problem is purely C++. Apparently vec->data[x] already gives you back a pointer, of which you are taking the address.

        EvgeE Offline
        EvgeE Offline
        Evge
        wrote on last edited by
        #3

        thanks @JohanSolo, you was right:

        your problem is purely C++. Apparently vec->data[x] already gives you back a pointer, of which you are taking the address.

        i try this >

        QString html("<html>"
        
                         "<head>"
                                "<title id = \'152\'>BIG title<title>"
                                "<script></script>"
                         "</head>"
                         "<body>"
                                "<p class=\'ID\'>15444552</p>"
                                "<div></div>"
                                "<p>after div</p>"
                                "<table></table>"
                         "</body>"
                         "</html>");
            GumboOutput* out = gumbo_parse(html.toUtf8().constData());
            GumboNode* node = out->root;
            QString htmlTag = QString::fromUtf8(gumbo_normalized_tagname(node->v.element.tag));
            GumboVector* vec = &node->v.element.children;
            qDebug() << htmlTag << " | children - " << vec->length;
        
            for (int x = 0; x < vec->length; x++){
                GumboNode* nodeX = static_cast<GumboNode*>(vec->data[x]);
                GumboVector *vecX = &nodeX->v.element.children;
                for (int y = 0; y < vecX->length; y++){
                    GumboNode* nodeY = static_cast<GumboNode*>(vecX->data[y]);
                    QString childTag = QString::fromUtf8(gumbo_normalized_tagname(nodeY->v.element.tag));
                    qDebug() << childTag << " | children - "<< nodeX->v.element.children.length;
                }
            }
        

        and I got an unexpected result :/
        "html" | children - 2
        "title" | children - 1

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Gumbo parser is not related to Qt you should ask the authors.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved