This will get you everything. That may not be what you want. I'm not sure of a way of getting only author specified styles.
#include <QtWebKit>
#include <QApplication>
#include <QtCore>
int main(int argc, char * argv[])
{
QWebPage page;
QWebFrame * frame = page.mainFrame();
frame->setHtml("<html><head><style>div { color:blue; }</style><body><div style=\"font-size:120%;\">Hello World!</div></body></html>");
QWebElement document = frame->documentElement();
QWebElementCollection elements = document.findAll("div");
foreach (QWebElement element, elements)
{
QString style
= element.
evaluateJavaScript("getComputedStyle(this).cssText").
toString();
{
if (keyvalue.length() == 2)
qDebug() << keyvalue.at(0).trimmed() << " = " << keyvalue.at(1).trimmed();
}
}
}
#include <QtWebKit>
#include <QApplication>
#include <QtCore>
int main(int argc, char * argv[])
{
QApplication a(argc, argv);
QWebPage page;
QWebFrame * frame = page.mainFrame();
frame->setHtml("<html><head><style>div { color:blue; }</style><body><div style=\"font-size:120%;\">Hello World!</div></body></html>");
QWebElement document = frame->documentElement();
QWebElementCollection elements = document.findAll("div");
foreach (QWebElement element, elements)
{
QString style = element.evaluateJavaScript("getComputedStyle(this).cssText").toString();
QStringList styles = style.split(';');
foreach(QString pair, styles)
{
QStringList keyvalue = pair.split(':');
if (keyvalue.length() == 2)
qDebug() << keyvalue.at(0).trimmed() << " = " << keyvalue.at(1).trimmed();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks