Using QWebkit To Retrieve Divs With A Specific Class
I posted the question below, trying to use the QDomDocument classes. I was advised to use the QWebkit instead, but I'm very confused how to do what I need to do with QWebkit. I've
Solution 1:
.pro
QT += webkitwidgets
main.cpp
#include <QApplication>
#include <QDebug>
#include <QWebView>
#include <QWebFrame>
#include <QWebElement>
int main( int argc, char *argv[] ) {
QApplication a(argc, argv);
QString l_html( "<html><body>"
"<div class='A'>div with class A</div>"
"<div class='B'>div with class B</div>"
"<div class='C'>div with class C</div>"
"<span class='A'>span with class A</span>"
"</body></html>" );
QWebView l_webView; // you can skip the QWebView if you dont want to show any widget
l_webView.page()->mainFrame()->setHtml( l_html );
QWebElement l_root( l_webView.page()->mainFrame()->documentElement() );
QWebElementCollection l_elements( l_root.findAll( ".a" ) );
foreach ( QWebElement l_e, l_elements ) {
// do what you want here
}
return a.exec();
}
Post a Comment for "Using QWebkit To Retrieve Divs With A Specific Class"