Qt - webkit - how to login programmatically

2020-06-06 03:08发布

问题:

I am making a web scraper. In that I need to login into my email account programatically. Can anybody say how to achieve that. I think "QNetworkAccesManager" and it's "get()" can make this. But, I don't know exactly. Somebody please shed a light on this issue.

Note: I am using Qt-4.7.2 + C++

回答1:

If the login is done in a web page then you should perform a post operation using QNetworkAccessManager::post() including the login fields in the data.

For instance:

QNetworkAccessManager network;
QByteArray loginData("user=myName&password=myPassword");
QNetworkRequest request(QUrl("http://mySite.com/login"));
QNetworkReply* pReply(network.post(request, loginData);

If the login is done via HTTP authentication method then you should connect the signal QNetworkAccessManager::authenticationRequired to one slot and fill the authentication data there.