I need to get title of webpage
-
wrote on 23 Jan 2017, 11:22 last edited by
Hi
I need to get title of webpage , for example : https://forum.qt.io/category/10/general-and-desktop , title : General and Desktop | Qt Forum .
How can i do?
Thanks -
-
@p3c0 Thanks
I used QWebEngineView before i send this topic.
I using QWebEnginePage and i get thie error :
:-1: error: Unknown module(s) in QT: webenginewidgets@Armin What is Qt version you're using? webenginewidgets is available since Qt 5.4
-
@Armin I wanted to know the Qt version, not QtCreator version.
Which Qt version did you install? -
@Armin I wanted to know the Qt version, not QtCreator version.
Which Qt version did you install? -
@Armin Did you install Qt WebEngine as well? It is not part of default installation. You can use Qt Maintenance Tool to install Qt WebEngine.
-
@Armin Did you install Qt WebEngine as well? It is not part of default installation. You can use Qt Maintenance Tool to install Qt WebEngine.
-
@Armin If you used Qt Online INstaller then you already have the Qt Maintenance Tool - see in Qt installation directory.
-
wrote on 5 Feb 2017, 11:36 last edited by
My maintance tool problem solved.
but i dont know how i must get title of a html page. -
@Armin You mean you want to extract title from:
<head> <title>General and Desktop | Qt Forum</title>
right?
Then you can just sent a GET request using http://doc.qt.io/qt-5/qnetworkaccessmanager.html and then parse the response (you can use a regular expression to extract the title from <title>...</title>).
From the link above:QNetworkRequest request; request.setUrl(QUrl("http://qt-project.org")); request.setRawHeader("User-Agent", "MyOwnBrowser 1.0"); QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>)));
-
@Armin You mean you want to extract title from:
<head> <title>General and Desktop | Qt Forum</title>
right?
Then you can just sent a GET request using http://doc.qt.io/qt-5/qnetworkaccessmanager.html and then parse the response (you can use a regular expression to extract the title from <title>...</title>).
From the link above:QNetworkRequest request; request.setUrl(QUrl("http://qt-project.org")); request.setRawHeader("User-Agent", "MyOwnBrowser 1.0"); QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>)));
-
@Armin Where did I say anything about set?
-
@jsulm Thanks
In this line if i am not mistaken you set the title
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
But i want to store the title in a QStringLifetime Qt Championwrote on 6 Feb 2017, 10:19 last edited by jsulm 2 Jun 2017, 10:22@Armin No this line does not set any titles, why do you think so? Did you read the documentation? You can remove this line. It is not needed for your use-case.
-
@Armin No this line does not set any titles, why do you think so? Did you read the documentation? You can remove this line. It is not needed for your use-case.
-
@jsulm Thanks
now , all i want is to get url in title ( <title> ... </title> ) and put it on QString.
@Armin You can use a regular expression after you got the response from the server to extract the title.
-
@Armin You can use a regular expression after you got the response from the server to extract the title.
-
@Armin Sorry, but you asked how to get the title of a web page, right?
What do you want to do with mp4 or pdf?