Using Qt to read and parse html files with QWebKit?

Posted by Alberto Toglia on Stack Overflow See other posts from Stack Overflow or by Alberto Toglia
Published on 2010-06-09T21:01:49Z Indexed on 2010/06/10 5:13 UTC
Read the original article Hit count: 484

Filed under:
|
|
|
|

I would like to read and parse certain elements of html files but I'm not interested in rendering it in any way. Basically I would like to go through all my div tags and get some of its style attributes. This is what I've done so far:

QWebPage page;
QWebFrame * frame = page.mainFrame();

QUrl fileUrl("localFile.html");
frame->setUrl(fileUrl);

QWebElement document = frame->documentElement();
QWebElementCollection elements = document.findAll("div");

foreach (QWebElement element, elements){
    std::cout << element.attribute("style").toStdString() << std::endl;
}

Doesn't show anything. I'm somewhat confused if I could use webkits this way. P.D.: I'm using a filechooser to pick the local html root.

© Stack Overflow or respective owner

Related posts about html

Related posts about css