Downloading website content
-
Hi,
I have a problem with downloading the website content. I just want to make the program downloaded from the content "<span class="file-icon1 archive"> text </ span>" and display it in the program.
When you compile the code pop up such errors:
@D:\qt\sprawdz_linki\mainwindow.cpp:-1: In member function 'void MainWindow::finished(bool)':D:\qt\sprawdz_linki\mainwindow.cpp:30: błąd: conversion from 'QWebPage*' to non-scalar type 'QWebElement' requested
QWebElement elem = qwv->page();
^D:\qt\sprawdz_linki\mainwindow.cpp:34: błąd: conversion from 'QWebElement' to non-scalar type 'QString' requested
QString test = elem;
^@And here is the code of the program:
@#include "mainwindow.h"
#include "ui_mainwindow.h"QWebView *qwv = new QWebView();
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QWebView *qwv = new QWebView();
qwv->setUrl(QUrl("http://download.qt-project.org/official_releases/online_installers/qt-opensource-linux-x64-1.6.0-online.run"));connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
}
void MainWindow::finished(bool)
{
QWebElement elem = qwv->page();elem.findFirst("span[class=\"file_icon1 archive\"]"); QString test = elem; ui->label->setText(test);
}
@[andreyc EDIT: Suspicious link was changed]
-
The error messages are pretty clear: you are performing an invalid conversion.
Try this code instead:
@
QWebElement elem = qwv->page()->mainFrame()->findFirstElement("span class=\“file-icon1 archive\”");
QString test = elem.toPlainText();
@Or something similar.
-
Images:
http://pics.tinypic.pl/i/00528/3xv7pbe9l8o7.png
Error :
@QWidget: Must construct a QApplication before a QWidget@Code :
@#include "mainwindow.h"
#include "ui_mainwindow.h"QWebView *qwv = new QWebView();
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QWebView *qwv = new QWebView();
qwv->setUrl(QUrl("http://download.qt-project.org/official_releases/online_installers/qt-opensource-linux-x64-1.6.0-online.run"));connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
}
void MainWindow::finished(bool)
{
//QWebElement elem = qwv->page();//elem.findFirst("span[class=\"file_icon1 archive\"]"); //QString test = elem; QWebElement elem = qwv->page()->mainFrame()->findFirstElement("span class=\"file-icon1 archive\""); QString test = elem.toPlainText(); ui->label->setText(test);
}
@@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QUrl>
#include <QtWebKitWidgets/QWebView>
#include <QtWebKit/QWebElement>
#include <QWebElementCollection>
#include <Qstring>
#include <QWebFrame>namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private slots:
void on_pushButton_clicked();
void finished(bool);private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
@[URL=http://www.tinypic.pl/3xv7pbe9l8o7][IMG]http://pics.tinypic.pl/i/00528/3xv7pbe9l8o7_t.jpg[/IMG][/URL]
-
Already fixed the error. The program starts correctly, but when you click on the button does not charge content <span class="file-icon1 archive">
-
Could someone help me