Extract information from a website (HTML) using Qt ?
-
I'd like extract the "information" in the "b" tag => 123456789
this is the HTML sorce :
@ <body>
<div>
<table>
<tbody>
<tr>
<td class="myclass">
<b>123456789</b>
</td>
</tr>
</tbody>
</table>
</div>
</body>@so , i try this :
@
void My_Test_Dialog::on_pushButton_clicked()
{QWebView *webview = new QWebView(parentWidget()); webview->load(QUrl("http://www.esesese.com")); webview->show(); // get HTML element information QWebElementCollection colls = webview->page()->mainFrame()->findAllElements("td.myclass b"); foreach(QWebElement elemento, colls) { ui->lineEdit_data->setText(elemento.toInnerXml()); } }
@
i have a form with a Button("call update") and a LineEdit, so if i click on the "update" button , automatically the LineEdit should set the Text "123456789". but my code doesn't work .. the Text of the LineEdit remains Emply.
I include this :
@#include <QtWebKit> #include <QtWebKitWidgets/QWebFrame> #include <QWebView>@
QT file.pro is :
@QT += core gui
QT += network
QT += webkit
QT += webkitwidgets@ -
findAllElements should be called after loadFinished is emitted with true.
-
use this in your .pro file:
@ QT += core gui webkit @