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. [OK] - QWebView - Getting source html or xml

[OK] - QWebView - Getting source html or xml

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 2.2k Views 1 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    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 something

    Here is the QWebView (#2 on the right) with text inside it (xml)
    https://www.dropbox.com/s/za8kv9ionowb5lc/readQWebViewSource.png

    Here 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!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      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"
      ""
      ""
      ...@


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        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.png

        inside a QWebView I get this:
        https://www.dropbox.com/s/26ij4xf36z8j4e4/insideQWebView.png

        I 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


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          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


          Free Indoor Cycling Software - https://maximumtrainer.com

          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