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. I want to extract elements from html using javascript
Forum Updated to NodeBB v4.3 + New Features

I want to extract elements from html using javascript

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 669 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.
  • R Offline
    R Offline
    rafae11
    wrote on 12 Mar 2014, 21:47 last edited by
    #1

    i am using a simple html example. i am using javascript to extract data and put it into a qvariant
    how do i convert the information to a string.

    @
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en">
    <head>
    <!-- You reference the resources with qrc:// -->
    <!-- Stylesheet reference -->
    <link rel="stylesheet" href="qrc:///css/view.css" />
    <!-- jQuery include -->
    [removed][removed]
    [removed][removed]

    &lt;title&gt;WebKit example&lt;/title&gt;
    

    </head>
    <body>
    <!-- Header -->
    <h1 id="header">Welcome</h1>
    <!-- Paragraph -->
    <p id="paragraph">Hello World!</p>
    <!-- Form -->
    <form id="form" action="#">
    <fieldset>
    <label for="text">Text</label>
    <!-- Text input -->
    <input id="text" type="text" />
    <!-- Submit button -->
    <input id="button" type="button" value="Submit!"/>
    </fieldset>
    </form>
    </body>
    </html>
    @

    i tried outputting variant as a string but i am not getting anything.
    output is just a QTextEdit

    @
    void MainWindow::gatherButtonClicked()
    {
    /**
    * Read the javascript to be executed to a string.
    */
    if(_gatherJS.isEmpty()) {
    _gatherJS = readFileToQString(QString("src/gather-data.js"));
    }
    else {
    _gatherJS = "Qt_QWET_gather();";
    }

    /** Run the javascript on the page and get results. */
    QVariant variant = ui->viewer->page()->mainFrame()->evaluateJavaScript("document.getElementById(\"header\")");
    /** We make sure that the results are there. */
    
    ui->output->append("getting element by id");
    ui->output->append(variant.toString());
    

    // if(!variant.isNull() &&
    // variant.type() == QVariant::List) {
    /** Ask for the acual list we're expecting. */
    // QList<QVariant> list = variant.toList();

        /** Update the entries in the list widget.*/
       // updatePList(_pList.data(), list);
    }
    

    }@

    1 Reply Last reply
    0

    1/1

    12 Mar 2014, 21:47

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved