You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, April 15th 2012, 11:58am

QtWebKit: Can’t load full html code from page

If we look at a plain source code of a website we will see that all ads, or most of them (flash, Google, others) are inserted as a JavaScript code. But if you look at the code in for example Firefox Firebug you will see that the JavaScript have been replaced with the HTML code of the add.
I want to load and parse this “full” html and I believed that Qt WebKit can do such stuff.

I tried to do it in that way:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PageLoader::PageLoader(const QUrl &url)
{
    mWebPage = new QWebPage();
    mWebPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    mWebPage->settings()->setAttribute(QWebSettings::PluginsEnabled, false);
    mWebPage->settings()->setAttribute(QWebSettings::AutoLoadImages, false);
    mWebPage->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
    connect(mWebPage->mainFrame(),SIGNAL(loadFinished(bool)), this, SLOT(processPage()));
    mWebPage->currentFrame()->load(url);
}
 
void PageLoader::processPage()
{
    QWebFrame* frame = mWebPage->currentFrame();
    QString webHtml = frame->toHtml();
    QFile file("/home/ostap/output.txt");
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out(&file);
    out << webHtml;
    emit finished();
}


But in output file I have only plain html with links to *.js files in script tags.

Where is my problem?