Results 1 to 6 of 6

Thread: Get web page content after QWebEngineView loadFinished()

  1. #1
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. QNetworkAccessManager manager;
    2. QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url)));
    3. QEventLoop event;
    4. connect(response,SIGNAL(finished()),&event,SLOT(quit()));
    5. event.exec();
    6. QString html = response->readAll(); // Source should be stored here
    To copy to clipboard, switch view to plain text mode 

    But the string 'html' comes out as empty. Could anyone please help in this ? Maybe some alternate way to get the content ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,938
    Thanks
    276
    Thanked 803 Times in 792 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Get web page content after QWebEngineView loadFinished()

    Quote Originally Posted by d_stranz View Post
    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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,938
    Thanks
    276
    Thanked 803 Times in 792 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Get web page content after QWebEngineView loadFinished()

    Quote Originally Posted by d_stranz View Post
    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.
    When I'm doing readAll() from the response, its coming empty. Is it possible to get the web page content from runJavaScript() function ?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,728
    Thanks
    13
    Thanked 1,608 Times in 1,535 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

Similar Threads

  1. QPrinter print QWebView content without any any page break.
    By Cupidvogel in forum Qt Programming
    Replies: 6
    Last Post: 21st May 2018, 00:51
  2. QWevView loadFinished iframes
    By Ini in forum Qt Programming
    Replies: 0
    Last Post: 26th January 2016, 18:22
  3. Capture full page with QWebEngineView
    By domusmaximus in forum Qt Programming
    Replies: 0
    Last Post: 15th January 2016, 21:50
  4. loadFinished() signal not emitted
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2013, 12:21
  5. Replies: 1
    Last Post: 24th March 2011, 16:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.