Results 1 to 4 of 4

Thread: QWebView - How to get DOM HTML

  1. #1
    Join Date
    Oct 2011
    Location
    Brazil, SC.
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QWebView - How to get DOM HTML

    So far I've been using "ui->browser->page()->mainFrame()->toHtml();"
    It returns fine the static HTML, but several pages use javascript, therefore a lot of parts are looking like this "Loading..." instead of the actual information.
    Is there anyway to get the DOM HTML?

    The specific piece of HTML that I'm trying to get right now is below;
    Qt Code:
    1. <tr class="data">
    2. <td class="desc timer">
    3. <span id="Countdown">Loading...</span>
    4. </td>
    5. </tr>
    To copy to clipboard, switch view to plain text mode 

    And the result I'm trying to get programatically would be something like this;
    Qt Code:
    1. <tr class="data">
    2. <td class="desc timer">
    3. <span id="Countdown">2h 44m 18s</span>
    4. </td>
    5. </tr>
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    LuÃ*s.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWebView - How to get DOM HTML

    Mybe you're just too quick and you're grabbing the html before JS has finished?

  3. The following user says thank you to Spitfire for this useful post:

    tachyon_me (24th October 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QWebView - How to get DOM HTML

    Use QWebFrame::findFirstElement() to query the DOM directly. Then you can traverse the tree using QWebElement API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Oct 2011
    Location
    Brazil, SC.
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebView - How to get DOM HTML

    @Spitfire this has nothing to do with it, the static HTML will never show any values updated by JS, it doesn't matter when you get it, the static html is "static". You have to check the DOM html to achieve this. But thanks for replying!

    @wysota Although I was expecting an example, I was able to solve my problem quickly after you assured me that the right way would be using the WebElement API. So thanks, I've solved my problem.

    A simple answer to my original poust would be:
    Qt Code:
    1. QWebElement e = ui->browser->page()->mainFrame()->findFirstElement("span#Countdown");
    2. qDebug() << e.toPlainText(); //a qDebug just to check it right now - it returns exactly the "2h 44m 18s" as I've mentioned above
    To copy to clipboard, switch view to plain text mode 

    Topic SOLVED.
    Last edited by lhg; 23rd October 2011 at 19:22.

Similar Threads

  1. Need help in Qwebview, find test in HTML page
    By keyurparekh in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2011, 14:29
  2. [4.7] QWebView + Qt aware HTML
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 25th October 2010, 10:49
  3. Parse RSS into html and display it in QWebView.
    By halvors in forum Qt Programming
    Replies: 11
    Last Post: 14th August 2010, 12:44
  4. Html page Display in QWebView
    By Tavit in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2010, 15:39
  5. How to save a Qwebview as an html file
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2009, 00:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.