Results 1 to 19 of 19

Thread: Rendered SourceCode from website

  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default Rendered SourceCode from website

    Hello,

    with QNetworkreply and readall() i can get the orginalsourcecode of a URL.

    But i need the rendered sourceCode which u can view with eg firebug. IS there any way to do that with qt?

    thx

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    Can you rephrase that?

    What is a "rendered source code"?

    Source code that is rendered syntax highlighted?
    Or do you mean the output of some rendering engine given a certain source code?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    modern websites are mosty scripted with javascript which adds content dynamically. When u click in your browser in such a website right-click view sourcecode it shows you the orginal-sourcode. When you view a website in firebug you see the "rendered" sourcecode with the added divs and stuff.

    I want the rendered sourcecode but i didn't find something in qt or c++ to achieve this. Can you help me there?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    You could try loading the web content into a QWebView and then using QWebFrame::toHtml() to get the string representation of the frame's DOM tree.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    Thats what i try atm but in my QT #include QWebpage is not available.

    I did the QT += webkitwidgets in the pro file. So i cannot do that. Do you now how to fix this?

    'QWebpage' was not declared in this scope

    genereally that sounds good but i hope you can help me make QWebpage work. I really dont know what to do now. I did what I need to do to implement it and i get an error...

    my version 3.6.0


    Added after 8 minutes:


    I did it now without the QWebpage variable but the srourcestring returns nothing except the basic html tree. The website is shown in the widgets. Whats the problem there? i never used that so far.


    Debugcode:

    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method
    qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto
    qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
    qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated
    "<html><head></head><body></body></html>"
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    ERROR: Font maps SPACE and ZERO WIDTH SPACE to the same glyph. Glyph width will not be overridden.
    platform\graphics\SimpleFontData.cpp(146) : void WebCore::SimpleFontData:latformGlyphInit()
    ERROR: Font maps SPACE and ZERO WIDTH SPACE to the same glyph. Glyph width will not be overridden.
    platform\graphics\SimpleFontData.cpp(146) : void WebCore::SimpleFontData:latformGlyphInit()
    LEAK: 6 JSLazyEventListener
    LEAK: 599 RenderObject
    LEAK: 2 Page
    LEAK: 7 Frame
    LEAK: 91 CachedResource
    LEAK: 1709 WebCoreNode





    sourcecode:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtWebKitWidgets>
    #include <QWebPage>
    #include <QWebFrame>
    #include <QDebug>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QWebView *view = new QWebView(parent);
    view->load(QUrl("http://www.qt.io/"));
    view->show();
    //QWebpage *page = view->page();
    QWebFrame *frame = view->page()->mainFrame();
    QString string = frame->toHtml();
    qDebug() << string;

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    Last edited by Ini; 23rd January 2016 at 14:12.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    You are trying to acccess the content before it is loaded.

    See QWebView::loadFinished().
    And if there are scripts running after load you might need to delay even further until they are done.

    Cheers,
    _

  7. #7
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    And how do I delay even further?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    For example using a timer.
    Or maybe the web content has some way of knowing when it is done.

    Cheers,
    _

  9. #9
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    i dont know it does not work even with the connect. Can you help me?
    qDebug() << string; in the code below does just nothing not even "" as debug. how can that be?

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QWebPage>
    4. #include <QWebFrame>
    5. #include <QDebug>
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12.  
    13. view = new QWebView(parent);
    14. connect(view,SIGNAL(loadFinished(bool)),this,SLOT(contentAvailable()));
    15. view->load(QUrl("http://www.qt.io/"));
    16. //view->show();
    17.  
    18. //QWebpage *page = view->page();
    19. }
    20.  
    21. MainWindow::~MainWindow()
    22. {
    23. delete ui;
    24. }
    25.  
    26. void MainWindow::contentAvailable()
    27. {
    28. qDebug() << "avail";
    29. QWebFrame *frame = view->page()->mainFrame();
    30. QString string = frame->toHtml();
    31. qDebug() << string;
    32. }
    To copy to clipboard, switch view to plain text mode 



    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QtWebKitWidgets>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. QWebView *view = NULL;
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23.  
    24. private slots:
    25. void contentAvailable();
    26. };
    27.  
    28. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 





    output/debug:

    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method
    qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto
    qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
    qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    avail
    DirectShowPlayerService::doRender: Unresolved error code 80040218
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    avail
    avail
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    avail
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
    avail
    ERROR: Font maps SPACE and ZERO WIDTH SPACE to the same glyph. Glyph width will not be overridden.
    platform\graphics\SimpleFontData.cpp(146) : void WebCore::SimpleFontData:latformGlyphInit()
    ERROR: Font maps SPACE and ZERO WIDTH SPACE to the same glyph. Glyph width will not be overridden.
    platform\graphics\SimpleFontData.cpp(146) : void WebCore::SimpleFontData:latformGlyphInit()
    LEAK: 6 JSLazyEventListener
    LEAK: 504 RenderObject
    LEAK: 2 Page
    LEAK: 7 Frame
    LEAK: 90 CachedResource
    LEAK: 1709 WebCoreNode
    Last edited by anda_skoa; 24th January 2016 at 16:43. Reason: missing [code] tags

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    The output also doesn't show "avail".

    Do you get output from other qDebug() statements?

    Cheers,
    _

    P.S.: use [code][/code] tags for posting code

  11. #11
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    what do you mean avail is shown in the output?

    i will next time use code statement. thx for advice

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    Quote Originally Posted by Ini View Post
    what do you mean avail is shown in the output?
    I wrote that it is not shown.
    Meaning that either qDebug() output is not shown in our output at all or that the slot was not called.

    But I see that I have overlooked it, it is well hidden in all kinds of unrelated stuff.

    What if you output some text together with the string, e.g. something like
    Qt Code:
    1. qDebug() << "html code:" << string;
    To copy to clipboard, switch view to plain text mode 
    Btw, "string" is a very bad variable name, the C++ Standard class for strings is called "string".

    In any case it looks like you need to do some debugging.

    Cheers,
    _

  13. #13
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    qDebug() << frame->toHtml();

    also debugs nothing. I dont know what to do. Seems like libarys not working correct. Or ist something wrong with my code?

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    That debug statement ist missing the fixed text to see if it really happens.

    Also you could get the QString from toHtml() into a variable and then output the string's isNull() and isEmpty() values.

    Also, trigger the slot from a button instead of the loading signal to see if you get output when you can visually confirm loading is done.

    Cheers,
    _

  15. #15
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    Tried all that. Same Problem still there.
    Problem with toHtml was qDebug is buggy there. Cause you can to toHtml in a playintextedit but not in debug. Only sometimes not always, must depend on some characters or so.

    Is there no way to get the rendered sourcecode?

    Every function currentFrame and mainFrame returns orginalsourcecode you can try yourself on a website that uses JS. Is there no way?


    Added after 1 21 minutes:


    Ok to make it 100% clear what i mean:
    There is a project called "Tab Browser" in the preinstalled ones for Qt.
    In that there is a button view->pagesource: thats not the code i need
    I need the code from Tools->Enable Web Inspector then rightclick on a element on the site and inspect. Thats the code i need.

    So there is a way. Can somebody introduce me how it works?
    Last edited by Ini; 6th February 2016 at 00:45.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    Hmm.
    Have you tried taking the QWebFrame::documentElement() and calling either toInnerXml() or toOuterXml() or traversing the tree?

    Cheers,
    _

  17. #17
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    As i said webframe has the wrong code in it i need the code like in the inpector in the frame. how can i get that code?
    Last edited by Ini; 6th February 2016 at 14:20.

  18. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rendered SourceCode from website

    Which is why I suggested trying the QWebElement tree.

    Cheers,
    _

  19. #19
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Rendered SourceCode from website

    I tried that before, with exact same result as i got now for this --> orgialsourcecode

    do you know how the inspector gets to that code?


    Added after 1 43 minutes:


    Ok problem was currentFrame() and mainFrame() does not get childiframes-sourcodes. How can somebody know that? Should be added to the documentation... Is there something to turn that on? Turn on load iframes?

    i need that cause one iframe sends something onLoad. And if it never loads cannot send it
    Last edited by Ini; 6th February 2016 at 23:11.

Similar Threads

  1. Text rendered as squares
    By SeppeVanNolle in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 9th November 2011, 15:17
  2. QFont is not rendered correctly in a different thread
    By PhilippM in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2011, 19:39
  3. Accessing Menubar in the sourcecode.
    By baluk in forum Newbie
    Replies: 1
    Last Post: 18th November 2010, 20:25
  4. changing svg graphic attributes once rendered
    By barrygp in forum Qt Programming
    Replies: 0
    Last Post: 13th December 2008, 02:09
  5. Webkit rendered fonts
    By carl in forum Qt Programming
    Replies: 0
    Last Post: 5th September 2008, 16:49

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.