[OK] - QWebView - Getting source html or xml
-
I am trying to retrieve the source html/xml of a QWebView.
When I use QDebug() on it, it always show me an empty QString.
However, I can see content in the QWebView, so i'm missing somethingHere is the QWebView (#2 on the right) with text inside it (xml)
https://www.dropbox.com/s/za8kv9ionowb5lc/readQWebViewSource.pngHere is my code that try to read the source of the QWebView :
@void DialogLogin::loginWebViewUrlChanged(){qDebug() << "URL_CHANGED:" << ui->webView_login->url(); if (ui->webView_login->url().toDisplayString().contains("current_account_cookie")) { qDebug() << "GOT IN!, PARSE XML"; qDebug() << ui->webView_login->page()->currentFrame()->url(); qDebug() << ui->webView_login->page()->currentFrame()->toHtml(); qDebug() << ui->webView_login->page()->currentFrame()->toPlainText(); qDebug() << ui->webView_login->page()->currentFrame()->documentElement().toPlainText(); qDebug() << ui->webView_login->page()->currentFrame()->documentElement().toOuterXml(); // loginAccepted(); }
}@
log :
@URL_CHANGED: QUrl( "http://localhost/index.php/api/account_rest/current_account_cookie" )
GOT IN!, PARSE XML
QUrl( "http://localhost/index.php/api/account_rest/current_account_cookie" )
""
""
""
"" @If you have any idea why it's printing "" instead of the current content, i'd appreciate some help, thanks!
-
I can now get the xml node name, but can't access the value inside it so far.
<last_activity>1405096946</last_activity>
I can only retrieve the node "last_activity" but not the value.. still looking@void DialogLogin::loginLoaded(){
qDebug() << "Login loaded!"; ui->webView_login->setFocus(); if (ui->webView_login->url().toDisplayString().contains("current_account_cookie")) { qDebug() << "GOT IN!, PARSE XML"; QWebFrame *frame = ui->webView_login->page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement element = document.firstChild(); while (!element.isNull()) { qDebug() << element.tagName(); /// no element.value()? qDebug() << element.firstChild().toPlainText(); element = element.nextSibling(); } }
}@
log :
@
"session_mt_id"
""
""
"session_mt_expire"
""
""
"last_mt_activity"
""
""
...@ -
Still looking for a reliable way to parse a XML document from a QwebView page:
I know the Xml is well formed, inside a browser I get this :
https://www.dropbox.com/s/e5h88hxmkhmeey9/restXml.pnginside a QWebView I get this:
https://www.dropbox.com/s/26ij4xf36z8j4e4/insideQWebView.pngI currently only get the node name and not the value inside Using this code :
@ QWebFrame *frame = ui->webView_login->page()->mainFrame();
QWebElement document = frame->documentElement();QWebElement element = document.firstChild(); while (!element.isNull()) { qDebug() << element.tagName(); /// this get the node name good /// how to get the element value ? qDebug() << element.firstChild().toPlainText(); element = element.nextSibling(); }@
Thanks
-
I have decided to use a QNetworkReply and use readyRead() on it instead of sending it to the QWebView. this way I can parse Xml using qxmlstreamreader