PDA

View Full Version : read data from website



sujan.dasmahapatra
26th June 2013, 10:43
In my website there is a table. I want to read the data from the 1st row 1st column of the table. Please tell me how can I read ? I have my QWebView. Please help. Thanks



connect(m_WebView, SIGNAL(loadFinished(bool)), this, SLOT(LoadFinishedCB(bool)));

m_WebView->setUrl(QUrl("http://www.mywebsite.com"));


In LoadFinishedCB I want to read the data. Please help.

ChrisW67
26th June 2013, 11:47
Acess the QWebFrame through your view and then use findFirstElement and related functions to access the QWebElements in the web page

sujan.dasmahapatra
26th June 2013, 16:00
Please check the code snippet below. I am trying to click on link in the page twice and then a table is loaded i want to read one data from the table from 1st row and 2nd column. Please help.


void MainWindow::LoadFinishedCB(bool ok)
{
QFile file("out.txt");
if (!file.open(QIODevice::WriteOnly))
return;
QTextStream out(&file);
button_click = m_WebView->page()->mainFrame()->documentElement().findAll("a");
qDebug() << button_click.count() << "\n";


button_click.at(5).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEven t( 'click', true, true );this.dispatchEvent(evObj);"
);


button_click.at(48).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEven t( 'click', true, true );this.dispatchEvent(evObj);"
);
//The above piece loads a new link in the same page.
//At this stage how can I make the program to wait till the page is //refreshed ???

out << m_WebView->page()->currentFrame()->toHtml() << "\n";

QWebElementCollection tables = m_WebView->page()->currentFrame()->findAllElements("table [id=layer_showhost]");
qDebug() << tables.count() << "\n";

QWebElementCollection trs = tables.first().document().findAll("tr");
qDebug() << trs.count() << "\n";


for(int m=0; m<trs.count(); m++)
{
QWebElementCollection tds = trs.at(m).document().findAll("td");
qDebug() << tds.count() << "\n";

for(int n=0; n<tds.count(); n++)
{
QWebElementCollection spans = tds.at(n).document().findAll("span");
qDebug() << spans.count() << "\n";

for(int z=0; z<spans.count(); z++)
{
out << spans.at(z).document().toPlainText() << " ";
}
}

}
}

ChrisW67
27th June 2013, 01:33
Does the QWebView (or something else) emit loadStarted() and then loadFinished() in response to clicking on the button?

sujan.dasmahapatra
27th June 2013, 11:32
no loadFinished is not being emitted.