I want to extract elements from html using javascript
-
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]<title>WebKit example</title>
</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); }
}@