PDA

View Full Version : Reading data from a website without specified url



Momergil
27th June 2017, 20:55
Hi!

I play a videogame called Mu Online. The server I play offers a website where, by clicking in a link, I can get a list of currently active players and the server they are logged into (https://www.muonline.com.br/ , then click in the number after "Onlines" in the right menu).

I'd like to create a light desktop app that would frequently (say 10s) monitors the active player table warning me when a given player is active via system tray icon.

The problem is I don't have much experience with dealing with web information and what I have probably doesn't work here: I only have some experience with QNetworkAcessManager downloading asset data from Yahoo! Finances, something that was easily accesible via a configurable web url. The mentioned website above, though, doesn't provide a specific link to the online players table: you may notice that, when accessing the table, the url doesn't change.

So how could I load this information from the website? I imagined that using QWebView I could archieve something, but I would still face the problem of reaching the online players table via QWebView.

So how could I do this? Any help will be appreciated.

d_stranz
27th June 2017, 21:24
The "Onlines" link shows it is a PHP script: https://www.muonline.com.br/onlines.php

I am guessing that the javascript that gets executed by the PHP does a database lookup and presents the results you see.

You could try executing this yourself by entering the URL, then parsing the HTML that gets returned. The list of users is in the "Onlines" table:



<table summary="Onlines" class="tabela borda">
<tr class="cor">
<td class="titulo"><a href="/onlines.php?ordem=1">Personagem</a></td>
<td class="titulo"><a href="/onlines.php?ordem=2">Classe</a></td>
<td class="titulo"><a href="/onlines.php?ordem=3">Guild</a></td>
<td class="titulo"><a href="/onlines.php?ordem=4">Sala</a></td>
<td class="titulo"><a href="/onlines.php">Conectado desde</a></td>
<td class="titulo"><a href="/onlines.php?ordem=6">VIP</a></td>
</tr>
<tr>
<td>_Darkness_</td>
<td>GM</td>
<td>Dream_T</td>
<td>VIP5</td>
<td>25/06/2017 06:04:00 </td>
<td><img src="imagens/vip_sim.gif" alt="Usu&aacute;rio VIP"></td>
</tr>
<tr class="cor">
<td>LauraBuff</td>
<td>ME</td>
<td>Dream_T</td>
<td>VIP5</td>
<td>25/06/2017 06:05:00 </td>
<td><img src="imagens/vip_sim.gif" alt="Usu&aacute;rio VIP"></td>
</tr>
<tr>
<td>Jisty</td>
<td>ME</td>
<td>Valhalla</td>
<td>VIP1</td>
<td>26/06/2017 02:05:00 </td>
<td><img src="imagens/vip_sim.gif" alt="Usu&aacute;rio VIP"></td>
</tr>

...

<tr>
<td>HyperX</td>
<td>MG</td>
<td></td>
<td>VIP4</td>
<td>27/06/2017 16:06:00 </td>
<td><img src="imagens/vip_sim.gif" alt="Usu&aacute;rio VIP"></td>
</tr>
</table>


In principle, it should not be much different from what you did with the Yahoo Finance lookup.

Momergil
28th June 2017, 22:40
Hello d_stranz,

first thanks for the reply. I was able to 'get' the link your provided, but when I read the content, I get no data (and no errors are mentioned):



void MainWindow::slotMainClock()
{
netAccMan->get(QNetworkRequest(QUrl("https://www.muonline.com.br/onlines.php")));
}

void MainWindow::slotDownloadFinished(QNetworkReply* reply)
{
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << "Error: " << reply->error();
return;
}

qDebug() << "Reading";
qDebug() << reply->readAll();
}


I couldn't figure out what's happening!

d_stranz
28th June 2017, 23:35
I couldn't figure out what's happening!

Sorry, can't help you either. Probably what happens in the browser is different from what occurs with your QNetworkRequest. As I remember, the capture of your web page also had references to a couple of javascript files - these may be doing client-side formatting of the PHP output, as described here. (https://stackoverflow.com/questions/12126684)