PDA

View Full Version : how to get source code of a web page



mmm286
16th March 2010, 12:33
Hi,

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

Many thanks and sorry for my english!

aamer4yu
16th March 2010, 12:36
QNetworkAccessManager::get

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

mmm286
16th March 2010, 15:35
Thanks.
I try with this:



QNetworkReply *reply = 0;

QNetworkRequest request;
request.setUrl(QUrl("http://www.marca.com"));
reply = manager->get(request);


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

JD2000
16th March 2010, 20:18
I have not actually tried it but I think

QTextBrowser *br = new QTextBrowser(this);
br->setText(reply->readAll());
should work

mmm286
17th March 2010, 10:58
Thanks again but doesn't works!






QNetworkAccessManager *manager = new QNetworkAccessManager(this);

QNetworkRequest request;
request.setUrl(QUrl("http://www.marca.com"));
reply = manager->get(request)


QTextBrowser *br = new QTextBrowser(this);

br->setText(reply->readAll());



Any help?

aamer4yu
17th March 2010, 11:08
Not sure if readAll will give you proper data instantly. Try to debug application..
also put some sleep before readAll and see what happens...

mmm286
17th March 2010, 12:10
I put



reply = manager->get(request);
qDebug()<<reply->readAll();
sleep( 60 );

texto2->setText(reply->readAll());
// reply->readAll()<<qDebug();

qDebug()<<reply->readAll();


But in the degub shows me ""


Any help? Thanks

JD2000
17th March 2010, 18:47
It looks like you are trying to use the network reply before the request has been completed.
The
reply = manager->get(request); has not yet received any data.

You need to wait until the manager signals that the request has been completed. You do this with
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); and include your

QTextBrowser *br = new QTextBrowser(this);
br->setText(reply->readAll()); in the replyFinished slot.