Get containts of website from QWebView using Qt 5.5.1
-
Hello
I'm using Qt 5.5.1 and I make a small browser using QWebview I want when I open a web page and press a button, it get the content of the website like I use get method in QnetworkAccessManager without using it because I want to get the data from website that have a login page so the URL not change when I log in and have not post method to PHP to get the data
I need any idea I can solve this problem or if I can get the current data from website open in the QWebview
Note
when I login into the website and get the data from it and press on view source code in firefox the data appear in the source code
Thanks in Advance -
When you login on the page your session data is stored. As long as you use the same session you can access the page however you want, including using
get()
. It's only important that you use the same instance of QNetworkAccessManager that you used to login and not create a new one. You can get that instance using networkAccessManager() member of the page.
If, for whatever reason, you want to use another instance (there's usually no good reason to do that) it's important to use the same cookie jar to store the session data. Use cookieJar() and setCookieJar() to share cookies between instances of QNAM. -
@Chris-Kawa Thanks for this hint and this what i tried
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); }
but i get the data of the first page without the login i want to get the page content after login please give me any hint or what i should do
Thanks