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. Parse HTML in Qt 5.7

Parse HTML in Qt 5.7

Scheduled Pinned Locked Moved Unsolved General and Desktop
htmlparsing
12 Posts 5 Posters 6.0k Views
  • 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.
  • A Offline
    A Offline
    AliReza Beytari
    wrote on 23 Jun 2016, 19:16 last edited by
    #1

    Hi.
    I have a QString which contain HTML Source Code. Like this :

    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<title>Hello World</title>
    </head>
    <body>
    	<input type="hidden" name="token" value="fc5e038d38a57032085441e7fe7010b0">
    </body>
    </html>
    

    So I want to get the value of hidden input. (with a function like find("input[name=token]").
    In Qt 5.4 I used to use QWebPage, QWebFrame, QWebElement, etc. But now I can't use them.

    How can I parse HTML codes ?!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jun 2016, 07:14 last edited by
      #2

      Hi,

      What about QString with a QRegularExpression ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 24 Jun 2016, 11:57
      0
      • V Offline
        V Offline
        VRonin
        wrote on 24 Jun 2016, 08:38 last edited by
        #3

        The entire Qt XML framework, including QXmlStreamReader classes can read HTML, you just need to set them to ignore errors due to root item not being unique

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • S SGaist
          24 Jun 2016, 07:14

          Hi,

          What about QString with a QRegularExpression ?

          A Offline
          A Offline
          AliReza Beytari
          wrote on 24 Jun 2016, 11:57 last edited by
          #4

          @SGaist But I don't want to use regular expressions!!

          @VRonin "QXmlStreamReader" doesn't have any "find" function !!

          B J 2 Replies Last reply 24 Jun 2016, 12:07
          0
          • A AliReza Beytari
            24 Jun 2016, 11:57

            @SGaist But I don't want to use regular expressions!!

            @VRonin "QXmlStreamReader" doesn't have any "find" function !!

            B Offline
            B Offline
            beecksche
            wrote on 24 Jun 2016, 12:07 last edited by beecksche
            #5

            @AliReza-Beytari

            You can subclass the QXmlStreamReader and implement your find - function. Like the code in the detailed desciption of the function

            QString SearchFunction()
            {
              QXmlStreamReader xml;
              ...
              while (!xml.atEnd()) {
                    xml.readNext();
                    // your search!
            
              }
              if (xml.hasError()) {
                    ... // do error handling
              }
            
            }
            
            
            A 1 Reply Last reply 24 Jun 2016, 12:15
            0
            • B beecksche
              24 Jun 2016, 12:07

              @AliReza-Beytari

              You can subclass the QXmlStreamReader and implement your find - function. Like the code in the detailed desciption of the function

              QString SearchFunction()
              {
                QXmlStreamReader xml;
                ...
                while (!xml.atEnd()) {
                      xml.readNext();
                      // your search!
              
                }
                if (xml.hasError()) {
                      ... // do error handling
                }
              
              }
              
              
              A Offline
              A Offline
              AliReza Beytari
              wrote on 24 Jun 2016, 12:15 last edited by
              #6

              @beecksche There is no way to use WebKit ?!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 24 Jun 2016, 12:16 last edited by
                #7

                Sure there is: build the module from sources.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A AliReza Beytari
                  24 Jun 2016, 11:57

                  @SGaist But I don't want to use regular expressions!!

                  @VRonin "QXmlStreamReader" doesn't have any "find" function !!

                  J Offline
                  J Offline
                  Joel Bodenmann
                  wrote on 24 Jun 2016, 12:30 last edited by Joel Bodenmann
                  #8

                  @AliReza-Beytari said:

                  @SGaist But I don't want to use regular expressions!!

                  May we ask why? Is this because you don't know how to build the regex pattern? If so, people are happy to help, there are also more than enough tools out there that will assist you with that :)
                  Whenever you have to find stuff in strings, regex is usually the way to go (unless it's some more primitive pattern - which isn't the case here).

                  @AliReza-Beytari said:

                  There is no way to use WebKit ?!

                  QtWebKit was replaced by QtWebEngine: https://wiki.qt.io/Porting_from_QtWebKit_to_QtWebEngine

                  Industrial process automation software: https://simulton.com
                  Embedded Graphics & GUI library: https://ugfx.io

                  A 1 Reply Last reply 24 Jun 2016, 12:55
                  1
                  • J Joel Bodenmann
                    24 Jun 2016, 12:30

                    @AliReza-Beytari said:

                    @SGaist But I don't want to use regular expressions!!

                    May we ask why? Is this because you don't know how to build the regex pattern? If so, people are happy to help, there are also more than enough tools out there that will assist you with that :)
                    Whenever you have to find stuff in strings, regex is usually the way to go (unless it's some more primitive pattern - which isn't the case here).

                    @AliReza-Beytari said:

                    There is no way to use WebKit ?!

                    QtWebKit was replaced by QtWebEngine: https://wiki.qt.io/Porting_from_QtWebKit_to_QtWebEngine

                    A Offline
                    A Offline
                    AliReza Beytari
                    wrote on 24 Jun 2016, 12:55 last edited by
                    #9

                    @Joel-Bodenmann I don't like to use regular expressions because Qt had some functions to parse HTML.

                    I know that QtWebKit was replaced by QtWebEngine, but I can't find any QWebEngineFrame or QWebEnginElement. (I found QWebEnginePage)

                    What is the replacement of QWebFrame and QWebElement ?!

                    J 1 Reply Last reply 24 Jun 2016, 13:02
                    0
                    • A AliReza Beytari
                      24 Jun 2016, 12:55

                      @Joel-Bodenmann I don't like to use regular expressions because Qt had some functions to parse HTML.

                      I know that QtWebKit was replaced by QtWebEngine, but I can't find any QWebEngineFrame or QWebEnginElement. (I found QWebEnginePage)

                      What is the replacement of QWebFrame and QWebElement ?!

                      J Offline
                      J Offline
                      Joel Bodenmann
                      wrote on 24 Jun 2016, 13:02 last edited by
                      #10

                      The article I linked explains this:

                      QWebFrame has been merged into QWebEnginePage
                      It is not possible to access sub-frames. Methods of the main QWebFrame are now available directly through the QWebEnginePage itself.
                      

                      It also contains corresponding example code.

                      Industrial process automation software: https://simulton.com
                      Embedded Graphics & GUI library: https://ugfx.io

                      A 1 Reply Last reply 24 Jun 2016, 14:02
                      1
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 24 Jun 2016, 13:51 last edited by
                        #11

                        Out of curiosity, are you using QtWebkit only to grab that token ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • J Joel Bodenmann
                          24 Jun 2016, 13:02

                          The article I linked explains this:

                          QWebFrame has been merged into QWebEnginePage
                          It is not possible to access sub-frames. Methods of the main QWebFrame are now available directly through the QWebEnginePage itself.
                          

                          It also contains corresponding example code.

                          A Offline
                          A Offline
                          AliReza Beytari
                          wrote on 24 Jun 2016, 14:02 last edited by
                          #12

                          @Joel-Bodenmann So I can just use "runJavaScript" function ?!

                          @SGaist No, that was just an example !! :D

                          1 Reply Last reply
                          0

                          4/12

                          24 Jun 2016, 11:57

                          topic:navigator.unread, 8
                          • Login

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