我使用Qt 5.5.1並使用QWebview製作小型瀏覽器我想在
時打開一個網頁並按下一個按鈕,它將獲取網站就像我用GET方法QnetworkAccessManager不使用它,因爲我想從網站上有一個登錄頁面的數據,所以當我登錄並沒有POST方法PHP獲取數據的URL不會改變。
例如當我登錄到www.login.com登錄顯示在同一鏈接上的數據
我需要任何想法我可以解決這個問題,或者如果我可以從QWebview
打開網站獲取當前數據 注意
當我登錄到網站,並獲取數據從它通過壓上查看源代碼在Firefox登錄數據出現在源代碼
這是我試過
從QWebView使用Qt 5.5.1獲取網站的內容
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
ui->setupUi(this);
ui->webView->load(QUrl("https://www.login.com")); // load page that have user name and password field
QWebPage *page = ui->webView->page(); // get the current page
manager = page->networkAccessManager(); // get the access manager from this page
}
MainWindow::~MainWindow() {
delete ui;
}
// get button
void MainWindow::on_pushButton_clicked() {
reply = manager->get(QNetworkRequest(QUrl("https://www.login.com"))); // make get now after login
connect(reply, SIGNAL(readyRead()),this,SLOT(readyRead()));
connect(reply, SIGNAL(finished()),this, SLOT(finish()));
}
void MainWindow::readyRead() {
QString str = QString::fromUtf8(reply->readAll()).trimmed(); // read the data
ui->plainTextEdit->appendPlainText(str);
}
但我得到第一個pag的數據沒有登錄。我想在登錄後獲取頁面內容,請告訴我應該做什麼。
更新
我認爲從Firefox在網頁源代碼中獲取文本輸入名稱,並使用QUrlQuery由結果作出後,以它的第一頁沒有登錄本的HTML代碼的一部分,我得到了它的名字
<label class="label-off" for="dwfrm_ordersignup_orderNo">Numéro de la commande</label> <input class="textinput required" id="anyname" type="text" name="UserName" value="" maxlength="2147483647" placeholder="* UserName" data-missing-error="Saisis ton numéro de commande. " data-parse-error="Ce contenu est invalide" data-range-error="Ce contenu est trop long ou trop court" required="required" />
它與其他字段的代碼相同。
代碼我在Qt的使用,使後
manager = new QNetworkAccessManager(this);
QUrlQuery query;
query.addQueryItem("UserName", "AAAA");
query.addQueryItem("Password", "BBB");
reply = manager->post(QNetworkRequest(QUrl(ui->lineEdit->text().trimmed())), query.toString().toUtf8());
connect(reply,&QNetworkReply::downloadProgress,this,&MainWindow::progress);
connect(reply,SIGNAL(readyRead()),this,SLOT(readyRead()));
connect(reply, SIGNAL(finished()), this,SLOT(finish()));
我嘗試後代碼PHP頁面我做和在這裏工作的問題,這只是HTML頁面
你可能要發個帖子方法到服務器,你需要分析的登錄頁面,看到的文本輸入的名稱和它當作一鍵'QUrlQuery',並通過這些相應的值(通常是名和密碼)。有關如何使用Qt完成post方法的示例已發佈[此處](http://stackoverflow.com/a/7445752/2014561)。 –
我更新什麼我都試過,請看一看這個 –
請參閱我的回答這個問題。 –