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. Html parser
Forum Updated to NodeBB v4.3 + New Features

Html parser

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 9 Posters 4.0k Views 5 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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 29 Oct 2018, 18:13 last edited by
    #8

    Hi
    Something like

    QString html = R"(
            <html>
            <head><title>Index of /satfiles/</title></head>
            <body bgcolor="white">
            <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
            <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
            <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
            <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
            </pre><hr></body>
            </html>)";
    
    QString regex = R"(href="([^"]*))";
    ----
     QRegularExpression re(regex);
      QRegularExpressionMatchIterator i = re.globalMatch(html);
      while (i.hasNext()) {
        QRegularExpressionMatch match = i.next();
        qDebug().noquote() << match.captured();
      }
    
    

    Gets you

    href="../
    href="test1.txt
    href="test2.txt
    href="yazmifiletest.ts
    

    you can use
    https://regexr.com/
    to tweak the expression to match exactly.

    S M 2 Replies Last reply 30 Oct 2018, 05:12
    3
    • S satyanarayana143
      29 Oct 2018, 05:33

      @SGaist said in Html parser:

      href="(.*)"

      can you give some example how to extract href with regex

      <html>
      <head><title>Index of /satfiles/</title></head>
      <body bgcolor="white">
      <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
      <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
      <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
      <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
      </pre><hr></body>
      </html>

      K Offline
      K Offline
      koahnig
      wrote on 29 Oct 2018, 19:04 last edited by
      #9

      @satyanarayana143

      Try out with the QRegularExpression example

      In contrast to the single line version of the QRegExp example you can test short text sections.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      2
      • M mrjj
        29 Oct 2018, 18:13

        Hi
        Something like

        QString html = R"(
                <html>
                <head><title>Index of /satfiles/</title></head>
                <body bgcolor="white">
                <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
                <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
                <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
                <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
                </pre><hr></body>
                </html>)";
        
        QString regex = R"(href="([^"]*))";
        ----
         QRegularExpression re(regex);
          QRegularExpressionMatchIterator i = re.globalMatch(html);
          while (i.hasNext()) {
            QRegularExpressionMatch match = i.next();
            qDebug().noquote() << match.captured();
          }
        
        

        Gets you

        href="../
        href="test1.txt
        href="test2.txt
        href="yazmifiletest.ts
        

        you can use
        https://regexr.com/
        to tweak the expression to match exactly.

        S Offline
        S Offline
        satyanarayana143
        wrote on 30 Oct 2018, 05:12 last edited by
        #10

        @mrjj

        thakk you for giving solution i want like this only i have solved my problem.

        1 Reply Last reply
        0
        • M mrjj
          29 Oct 2018, 18:13

          Hi
          Something like

          QString html = R"(
                  <html>
                  <head><title>Index of /satfiles/</title></head>
                  <body bgcolor="white">
                  <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
                  <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
                  <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
                  <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
                  </pre><hr></body>
                  </html>)";
          
          QString regex = R"(href="([^"]*))";
          ----
           QRegularExpression re(regex);
            QRegularExpressionMatchIterator i = re.globalMatch(html);
            while (i.hasNext()) {
              QRegularExpressionMatch match = i.next();
              qDebug().noquote() << match.captured();
            }
          
          

          Gets you

          href="../
          href="test1.txt
          href="test2.txt
          href="yazmifiletest.ts
          

          you can use
          https://regexr.com/
          to tweak the expression to match exactly.

          M Offline
          M Offline
          ManiRon
          wrote on 23 Feb 2019, 05:52 last edited by
          #11

          @mrjj said in Html parser:

          R

          sir in this what does R mean for in the QString html

          A 1 Reply Last reply 23 Feb 2019, 06:39
          0
          • M ManiRon
            23 Feb 2019, 05:52

            @mrjj said in Html parser:

            R

            sir in this what does R mean for in the QString html

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 23 Feb 2019, 06:39 last edited by
            #12

            @ManiRon: https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial

            Qt has to stay free or it will die.

            M 1 Reply Last reply 23 Feb 2019, 06:53
            1
            • A aha_1980
              23 Feb 2019, 06:39

              @ManiRon: https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial

              M Offline
              M Offline
              ManiRon
              wrote on 23 Feb 2019, 06:53 last edited by
              #13

              @aha_1980 said in Html parser:

              https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial

              error: 'R' was not declared in this scope
              QString qHtml = R"(<button type="button">Click Me!</button>)";
              ^

              M 1 Reply Last reply 23 Feb 2019, 09:08
              0
              • M ManiRon
                23 Feb 2019, 06:53

                @aha_1980 said in Html parser:

                https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial

                error: 'R' was not declared in this scope
                QString qHtml = R"(<button type="button">Click Me!</button>)";
                ^

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 23 Feb 2019, 09:08 last edited by
                #14

                @ManiRon
                Hi
                Code seems fine - so it must be compiler version.

                Is it an older Qt / Compiler ?

                Its a c++ 11 feature with R (raw strings)

                M 1 Reply Last reply 23 Feb 2019, 09:43
                1
                • M mrjj
                  23 Feb 2019, 09:08

                  @ManiRon
                  Hi
                  Code seems fine - so it must be compiler version.

                  Is it an older Qt / Compiler ?

                  Its a c++ 11 feature with R (raw strings)

                  M Offline
                  M Offline
                  ManiRon
                  wrote on 23 Feb 2019, 09:43 last edited by
                  #15

                  @mrjj its Qt 5.5

                  M 1 Reply Last reply 23 Feb 2019, 09:49
                  0
                  • M ManiRon
                    23 Feb 2019, 09:43

                    @mrjj its Qt 5.5

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 23 Feb 2019, 09:49 last edited by
                    #16

                    @ManiRon
                    Hi
                    Can you try to add
                    CONFIG += c++11
                    in your .pro file
                    then run qmake and rebuild all (from menu) and see if it accepts it then.

                    M 2 Replies Last reply 23 Feb 2019, 09:50
                    0
                    • M mrjj
                      23 Feb 2019, 09:49

                      @ManiRon
                      Hi
                      Can you try to add
                      CONFIG += c++11
                      in your .pro file
                      then run qmake and rebuild all (from menu) and see if it accepts it then.

                      M Offline
                      M Offline
                      ManiRon
                      wrote on 23 Feb 2019, 09:50 last edited by
                      #17

                      @mrjj said in Html parser:

                      CONFIG += c++11

                      i will check and say sir

                      1 Reply Last reply
                      0
                      • M mrjj
                        23 Feb 2019, 09:49

                        @ManiRon
                        Hi
                        Can you try to add
                        CONFIG += c++11
                        in your .pro file
                        then run qmake and rebuild all (from menu) and see if it accepts it then.

                        M Offline
                        M Offline
                        ManiRon
                        wrote on 23 Feb 2019, 09:52 last edited by ManiRon
                        #18

                        @mrjj

                        1. It worked sir
                        2. But i am trying to create a button as you can see in the previous code its just displaying the text click me and not the button in the HTML file
                        3. I know that in the list of attribute supported by QT <button> tag is not there whether we can make QT to make work on this
                        M 1 Reply Last reply 23 Feb 2019, 09:59
                        0
                        • M ManiRon
                          23 Feb 2019, 09:52

                          @mrjj

                          1. It worked sir
                          2. But i am trying to create a button as you can see in the previous code its just displaying the text click me and not the button in the HTML file
                          3. I know that in the list of attribute supported by QT <button> tag is not there whether we can make QT to make work on this
                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 23 Feb 2019, 09:59 last edited by mrjj
                          #19

                          @ManiRon
                          Hi
                          Super. so was just c+11 support.
                          The QT widgets cannot draw html Buttons so if you
                          view them in textEdit/Browser no buttons can be shown.

                          I know no easy way to have buttons, but you can try with
                          Qt WebEngine
                          instead and see if it likes it.

                          M 1 Reply Last reply 23 Feb 2019, 11:23
                          1
                          • M mrjj
                            23 Feb 2019, 09:59

                            @ManiRon
                            Hi
                            Super. so was just c+11 support.
                            The QT widgets cannot draw html Buttons so if you
                            view them in textEdit/Browser no buttons can be shown.

                            I know no easy way to have buttons, but you can try with
                            Qt WebEngine
                            instead and see if it likes it.

                            M Offline
                            M Offline
                            ManiRon
                            wrote on 23 Feb 2019, 11:23 last edited by ManiRon
                            #20

                            @mrjj as i have not worked on it any sample will be available for Qtwebengine which can be help full to understand it

                            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