Get web page content after QWebEngineView loadFinished()
Hi,
I need to get the whole web page content after receiving loadFinished() signal for that URL. I need to store the web page content in a string or a file and then use it to access some elements from the web page.
I have researched about this and tried:
Code:
QNetworkAccessManager manager;
QNetworkReply
*response
= manager.
get(QNetworkRequest
(QUrl(url
)));
connect(response,SIGNAL(finished()),&event,SLOT(quit()));
event.exec();
QString html
= response
->readAll
();
// Source should be stored here
But the string 'html' comes out as empty. Could anyone please help in this ? Maybe some alternate way to get the content ?
Re: Get web page content after QWebEngineView loadFinished()
This is probably one of the most confused pieces of code I have read on this forum. Do you mean to say that all of this code is within the scope of a single method? Exactly what have you "researched" to make you think this code would produce the result you want?
Re: Get web page content after QWebEngineView loadFinished()
Quote:
Originally Posted by
d_stranz
This is probably one of the most confused pieces of code I have read on this forum. Do you mean to say that all of this code is within the scope of a single method? Exactly what have you "researched" to make you think this code would produce the result you want?
I was searching about how to get the web page content in qt and came across this code block and tried it. I know there is runJavaScript() function as well but when i used it with getElementById it did not work. Also, there was something related to jquery should be running on the page but I'm not able to understand that fully.
Re: Get web page content after QWebEngineView loadFinished()
Maybe you should start with an example like this,. Or something like this.
I found the example that you copied on Qt Forum. It really is a terrible solution.
Re: Get web page content after QWebEngineView loadFinished()
Quote:
Originally Posted by
d_stranz
When I'm doing readAll() from the response, its coming empty. Is it possible to get the web page content from runJavaScript() function ?
Re: Get web page content after QWebEngineView loadFinished()
QWebEngineView and QWebEngineView::loadFinished() (from your subject and first post) and your code using QNetworkAccessManager directly are totally unreleated related to each other.
If you are actually using QWebEngineView then you can get the HTML from the view's QWebPage through its toHtml() method.
If you fetching the web URL using QNetworkAcessManage and QNetworkRequest:
There is more than one reason a QNetworkReply might finish with an empty response. Errors are one. Have you checked for those? A deliberately empty response is another.