Hi,
i'm struggling with this problem for hours now...i hope someone can enlighten me!
I'm fetching a HTML-page with an HTTP-Request and read it with QNetworkReply::readAll(). So far so good.
Then i want to "parse" (get some information of some elements) the HTML-page using QWebPage/QWebFrame.
And there is my problem. I tried the following, but all the time an empty QWebElementCollection is returned:
QWebView view;
view.load( url );
QWebElementCollection elements = view.page()->mainFrame()->findAllElements("div");
QWebView view;
view.load( url );
QWebElementCollection elements = view.page()->mainFrame()->findAllElements("div");
To copy to clipboard, switch view to plain text mode
QWebPage page;
page.mainFrame()->setHtml( reply.readAll() ); //setContent doesn't work either
QWebElementCollection elements = page.mainFrame()->findAllElements("div");
QWebPage page;
page.mainFrame()->setHtml( reply.readAll() ); //setContent doesn't work either
QWebElementCollection elements = page.mainFrame()->findAllElements("div");
To copy to clipboard, switch view to plain text mode
Only when i set the HTML-Code directly it works just fine as expected and i get the desired elements:
QWebPage page;
page.
mainFrame()->setContent
( QString("<html>...</html>") );
QWebElementCollection elements = page.mainFrame()->findAllElements("div");
QWebPage page;
page.mainFrame()->setContent( QString("<html>...</html>") );
QWebElementCollection elements = page.mainFrame()->findAllElements("div");
To copy to clipboard, switch view to plain text mode
So why doesn't it work when i set the content as QByteArray? Is there some coding issue?
Note: when i load the same QByteArray into a QWebView it displays just fine.
Hope someone can finally help me with this!
EDIT:
i found out that loadFinished(bool) signal is emited with "false" for the non working cases (with the QByteArray). Thus i subclasse QWebPage and reimplemented the supportsExtension() and extension() in hope to get some info whats going wrong but the methods don't get even called (tested with debugger).
virtual bool supportsExtension( Extension extension ) const {
return extension == ErrorPageExtension;
}
virtual bool extension ( Extension extension, const ExtensionOption * option = 0, ExtensionReturn * output = 0 )
{
if (extension != QWebPage::ErrorPageExtension)
return false;
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
qDebug() << "Error loading " << qPrintable(errorOption->url.toString());
if(errorOption->domain == QWebPage::QtNetwork)
qDebug() << "Network error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::Http)
qDebug() << "HTTP error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::WebKit)
qDebug() << "WebKit error (" << errorOption->error << "): ";
qDebug() << qPrintable(errorOption->errorString);
return true;
}
virtual bool supportsExtension( Extension extension ) const {
return extension == ErrorPageExtension;
}
virtual bool extension ( Extension extension, const ExtensionOption * option = 0, ExtensionReturn * output = 0 )
{
if (extension != QWebPage::ErrorPageExtension)
return false;
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
qDebug() << "Error loading " << qPrintable(errorOption->url.toString());
if(errorOption->domain == QWebPage::QtNetwork)
qDebug() << "Network error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::Http)
qDebug() << "HTTP error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::WebKit)
qDebug() << "WebKit error (" << errorOption->error << "): ";
qDebug() << qPrintable(errorOption->errorString);
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks