Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Parse HTML in Qt 5.7

    General and Desktop
    html parsing
    5
    12
    5158
    Loading More Posts
    • 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
      AliReza Beytari last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • V
          VRonin last edited by

          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 Reply Quote 4
          • A
            AliReza Beytari @SGaist last edited by

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

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

            beecksche Joel Bodenmann 2 Replies Last reply Reply Quote 0
            • beecksche
              beecksche @AliReza Beytari last edited by beecksche

              @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 Reply Quote 0
              • A
                AliReza Beytari @beecksche last edited by

                @beecksche There is no way to use WebKit ?!

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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 Reply Quote 0
                  • Joel Bodenmann
                    Joel Bodenmann @AliReza Beytari last edited by Joel Bodenmann

                    @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 Reply Quote 1
                    • A
                      AliReza Beytari @Joel Bodenmann last edited by

                      @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 ?!

                      Joel Bodenmann 1 Reply Last reply Reply Quote 0
                      • Joel Bodenmann
                        Joel Bodenmann @AliReza Beytari last edited by

                        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 Reply Quote 1
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          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 Reply Quote 0
                          • A
                            AliReza Beytari @Joel Bodenmann last edited by

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

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

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post