How i can get all "div" elements from webpage?
-
@ ui->webView->load(QUrl("http://stackoverflow.com"));
..................................
QWebElementCollection collection = frame->findAllElements("div");
foreach (QWebElement element, collection)
{
qDebug() << element.attribute("id");
}@
How i can get all "div" elements from webpage?I want get result:
div id = test1
div id = test2 -
QWebView::Load() operates asynchronously, thus you have to wait until the page is fully loaded before you can get all the elements.
Do this by listen to the "QWebView::loadFinished()":http://qt-project.org/doc/qt-4.8/qwebview.html#loadFinished signal. -
I used "QWebFrame::findAllElements()":http://qt-project.org/doc/qt-4.8/qwebframe.html#findAllElements succesfully for this. Of course as raven-worx pointed out the page must first finish loading.
@
QWebElementCollection result = yourWebView->page()->mainFrame()->findAllElements("div");
@