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 response of QNetworkAccessManager using QtWebEngine
Forum Updated to NodeBB v4.3 + New Features

Parse response of QNetworkAccessManager using QtWebEngine

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 2.8k Views 2 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.
  • VolebabV Offline
    VolebabV Offline
    Volebab
    wrote on last edited by
    #1

    Hi guys, I'm making a request using QNetworkAccessManager to download a page and I get the html of that page with all the tags. That is how the page looks like:

    <!DOCTYPE html>
    <html>
    <head>
    	<title>Webservice</title>
    </head>
    <body>
    <p>
    	USER = JOHN DOE
    	AGE = 21
    	MOTHER = JANE DOE
    	BROTHERS = 2
    </p>
    </body>
    </html>
    

    I want to load this HTML in a QWebEngine (that is new to me) and get the content that is inside the <p>.
    The tricky part for me is, I want to parse that content like key = value and put in a QMap<QString, QString>;
    For example, in this case it would be: QMap<QString, QString> info = { { "USER": "JOHN DOE" } };
    How can I do that? I already have the content using the QNetworkAccessManager, now the only thing left is get the content of the tag and parse it into a QMap.

    kshegunovK 1 Reply Last reply
    0
    • VolebabV Volebab

      Hi guys, I'm making a request using QNetworkAccessManager to download a page and I get the html of that page with all the tags. That is how the page looks like:

      <!DOCTYPE html>
      <html>
      <head>
      	<title>Webservice</title>
      </head>
      <body>
      <p>
      	USER = JOHN DOE
      	AGE = 21
      	MOTHER = JANE DOE
      	BROTHERS = 2
      </p>
      </body>
      </html>
      

      I want to load this HTML in a QWebEngine (that is new to me) and get the content that is inside the <p>.
      The tricky part for me is, I want to parse that content like key = value and put in a QMap<QString, QString>;
      For example, in this case it would be: QMap<QString, QString> info = { { "USER": "JOHN DOE" } };
      How can I do that? I already have the content using the QNetworkAccessManager, now the only thing left is get the content of the tag and parse it into a QMap.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Volebab

      now the only thing left is get the content of the tag and parse it into a QMap.

      If you have the HTML, you could try to use the QDomDocument class and load it there. Then you can traverse the document by tags like in the example from the documentation.

      Read and abide by the Qt Code of Conduct

      VolebabV 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @Volebab

        now the only thing left is get the content of the tag and parse it into a QMap.

        If you have the HTML, you could try to use the QDomDocument class and load it there. Then you can traverse the document by tags like in the example from the documentation.

        VolebabV Offline
        VolebabV Offline
        Volebab
        wrote on last edited by
        #3

        @kshegunov Thank you, but what about the tricky part? I mean, parse the key values to a qmap?

        kshegunovK 1 Reply Last reply
        0
        • VolebabV Volebab

          @kshegunov Thank you, but what about the tricky part? I mean, parse the key values to a qmap?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Volebab
          Well, depends on the format, but if it's like shown (i. e. being a simple one) you can split the <p> tag's contents first by newlines, so you get each pair NAME = VALUE. And then for each such pair you can split it again by the equality sing, so you retrieve the two parts - the name and the value.

          Read and abide by the Qt Code of Conduct

          VolebabV 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @Volebab
            Well, depends on the format, but if it's like shown (i. e. being a simple one) you can split the <p> tag's contents first by newlines, so you get each pair NAME = VALUE. And then for each such pair you can split it again by the equality sing, so you retrieve the two parts - the name and the value.

            VolebabV Offline
            VolebabV Offline
            Volebab
            wrote on last edited by Volebab
            #5

            @kshegunov You are right, how couldn't I thought about that before? I thought about using regex like (.*) = (.*) but I think that it will be more expansive than using split.

            kshegunovK 1 Reply Last reply
            0
            • VolebabV Volebab

              @kshegunov You are right, how couldn't I thought about that before? I thought about using regex like (.*) = (.*) but I think that it will be more expansive than using split.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @Volebab said:

              I thought about using regex like (.) = (.)

              Regex would probably work as well. So it's a matter of choice I suppose.

              Read and abide by the Qt Code of Conduct

              VolebabV 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @Volebab said:

                I thought about using regex like (.) = (.)

                Regex would probably work as well. So it's a matter of choice I suppose.

                VolebabV Offline
                VolebabV Offline
                Volebab
                wrote on last edited by
                #7

                @kshegunov Which one is faster? Do you have an idea?

                kshegunovK 1 Reply Last reply
                0
                • VolebabV Volebab

                  @kshegunov Which one is faster? Do you have an idea?

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @Volebab said:

                  Which one is faster? Do you have an idea?

                  No, not really. Usually regex expressions are somewhat slower, but I can't be sure for this case. If it's really important you should write a simple program to benchmark it.

                  Read and abide by the Qt Code of Conduct

                  VolebabV 1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    @Volebab said:

                    Which one is faster? Do you have an idea?

                    No, not really. Usually regex expressions are somewhat slower, but I can't be sure for this case. If it's really important you should write a simple program to benchmark it.

                    VolebabV Offline
                    VolebabV Offline
                    Volebab
                    wrote on last edited by
                    #9

                    @kshegunov I will, but anyway, I did it thanks to you.

                    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