Parse response of QNetworkAccessManager using QtWebEngine
-
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 aQMap<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. -
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.
-
@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 pairNAME = 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. -
@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.