Reputation: 1
I am trying to import data from an html webpage into Matlab. I have come across a function "getTableFromWeb". It looks pretty cool. The problem is when I use a browser for example Firefox I can see the data. But when use this function it can't find any table. Even when I save the html file from browser it only save the code. There is no data. I don't know anything about java html programming. But I read many many relevant questions but I can't find the answer to my problem. I used Inspect Element in Firefox. It shows in the Debugger, the bootstrap.js and jquery.js and list.html. I appreciate any help.
get("http://laaablaaablaaablaaaab is similiar to the url I use to see the data but not identical.
Thanks in advance.
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>laablaablaab/title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"/>
<style>
.table{
font-size: 8px;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<ul class="nav navbar-nav">
<li><a href="index.html">Home</a></li>
<li><a href="register.html">Register name</a></li>
<li><a href="guide.html">Guide</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Time</th>
<th>U L1</th>
<th>Powerlvl adj max</th>
<th>VAR Q<small>abs</small></th>
<th>VAR Q<small>abs</small> lead or lag</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
<tfoot>
<nav>
<ul class="pager">
<li class="previous disabled"><a id="pvpg" href="#"><span aria-hidden="true">←</span> Older</a>
</li>
<li class="next"><a id="nxtpg" href="#">Newer <span aria-hidden="true">→</span></a></li>
</ul>
</nav>
</tfoot>
</table>
</div>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script>
var index = 0;
var Name = getQueryParameters().name;
var pages = 50;
var num = getNumberMeasurements(inverterName);
var nextpager = document.getElementById("nxtpg");
var previouspager = document.getElementById("pvpg");
getMeasurements(inName, index, pages);
nextpager.onclick = function () {
if (index >= num / pages)
return;
index++;
getMeasurements(Name, index, pages);
};
previouspager.onclick = function () {
if (index == 0)
return;
index--;
getMeasurements(Name, index, pages);
};
function handlePagerBtns() {
var calculated = 0;
if (num > 0){
calculated = Math.ceil(num/pages);
}
if (index >= calculated) {
var li = nextpager.parentNode;
li.className = "next disabled";
}
else {
var li = nextpager.parentNode;
li.className = "next";
}
if (index == 0) {
var li = previouspager.parentNode;
li.className = "previous disabled"
} else {
var li = previouspager.parentNode;
li.className = "previous"
}
}
function getNumberMeasurements(name) {
var num = 1000;
return num;
}
function getMeasurements(name, skip, top) {
handlePagerBtns();
var tbody = document.getElementById("tbody");
tbody.innerHTML = "";
$.get("http://laaablaaablaaablaaaab('" + name + "')/Measurement?$orderby=LogTime+desc&$skip=" + skip*top + "+&$top=" + top, {})
.done(function (data) {
data.value.forEach(function (measurement) {
var trow = document.createElement("TR");
for (var k in measurement) {
if (k == "_Name")
continue;
var tcell = document.createElement("TD");
if (k == "Id" || k == "LogTime") {
tcell.innerHTML = measurement[k];
}
else if (k == "ReactivePowerQabsIsLag" || k == "ReactivePowerCosPhiIsLag") {
tcell.innerHTML = measurement[k];
}
else {
if (measurement[k] != null)
tcell.innerHTML = measurement[k].toFixed(2);
}
trow.appendChild(tcell);
}
tbody.appendChild(trow);
});
});
}
function getQueryParameters() {
var queryString = location.search.replace("?", "");
var params = queryString.split("&");
var queryParams = {};
params.forEach(function (parm) {
var array = parm.split("=");
queryParams[array[0]] = array[1];
});
`
Upvotes: 0
Views: 478
Reputation: 1473
The issue is that the table is populated by javascript, but your function doesn't evaluate the javascript, it just pulls in the HTML. Check out http://phantomjs.org/ for a common solution written in Javascript. If a solution is built using the Phantom.js command line interface, you could access it from MATLAB via the system() function.
Upvotes: 0