0

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.

1 Answer 1

1

If you don't want to render, why use QWeb* classes? Use simple QFile and maybe QXmlStreamReader?

Sign up to request clarification or add additional context in comments.

1 Comment

I had already done it reading characters one by one, it was so ugly I wanted to clean it with Qt. I was hoping that maybe Qt had some high level utilities for html parsing. The QXmlStreamReader seems like a good idea, but for the styles I think I'll need to use regular expressions if I want to do be elegant? That makes me want to stay with my implementation... (afraid face)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.