Results 1 to 8 of 8

Thread: how to get source code of a web page

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default how to get source code of a web page

    Hi,

    I would like to kwowh how could I get source code of a web page.

    Many thanks and sorry for my english!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get source code of a web page

    QNetworkAccessManager::get
    Just look at some examples in Qt Demo.. like web browser...you might see the source in reply.

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: how to get source code of a web page

    Thanks.
    I try with this:

    Qt Code:
    1. QNetworkReply *reply = 0;
    2.  
    3. QNetworkRequest request;
    4. request.setUrl(QUrl("http://www.marca.com"));
    5. reply = manager->get(request);
    To copy to clipboard, switch view to plain text mode 

    But I dont know how get the source code of reply and show in a qtextbrowser
    any help?

  4. #4
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get source code of a web page

    I have not actually tried it but I think
    Qt Code:
    1. QTextBrowser *br = new QTextBrowser(this);
    2. br->setText(reply->readAll());
    To copy to clipboard, switch view to plain text mode 
    should work

  5. #5
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: how to get source code of a web page

    Thanks again but doesn't works!




    Qt Code:
    1. QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    2.  
    3. QNetworkRequest request;
    4. request.setUrl(QUrl("http://www.marca.com"));
    5. reply = manager->get(request)
    6.  
    7.  
    8. QTextBrowser *br = new QTextBrowser(this);
    9.  
    10. br->setText(reply->readAll());
    To copy to clipboard, switch view to plain text mode 

    Any help?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get source code of a web page

    Not sure if readAll will give you proper data instantly. Try to debug application..
    also put some sleep before readAll and see what happens...

  7. #7
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: how to get source code of a web page

    I put

    Qt Code:
    1. reply = manager->get(request);
    2. qDebug()<<reply->readAll();
    3. sleep( 60 );
    4.  
    5. texto2->setText(reply->readAll());
    6. // reply->readAll()<<qDebug();
    7.  
    8. qDebug()<<reply->readAll();
    To copy to clipboard, switch view to plain text mode 
    But in the degub shows me ""


    Any help? Thanks

  8. #8
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get source code of a web page

    It looks like you are trying to use the network reply before the request has been completed.
    The
    Qt Code:
    1. reply = manager->get(request);
    To copy to clipboard, switch view to plain text mode 
    has not yet received any data.

    You need to wait until the manager signals that the request has been completed. You do this with
    Qt Code:
    1. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    To copy to clipboard, switch view to plain text mode 
    and include your
    Qt Code:
    1. QTextBrowser *br = new QTextBrowser(this);
    2. br->setText(reply->readAll());
    To copy to clipboard, switch view to plain text mode 
    in the replyFinished slot.

Similar Threads

  1. Download Page Source of Website
    By AjRomano in forum Newbie
    Replies: 3
    Last Post: 11th March 2010, 06:22
  2. Source code
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2008, 09:04
  3. Read the source page of url? SOLVED
    By triperzonak in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2008, 09:44
  4. source code
    By Colx007 in forum Newbie
    Replies: 5
    Last Post: 19th December 2007, 09:15

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.