0

我正在尝试将数据从 html 网页导入 Matlab。我遇到了一个函数“getTableFromWeb”。它看起来很酷。问题是当我使用浏览器(例如 Firefox)时,我可以看到数据。但是当使用此功能时,它找不到任何表。即使我从浏览器保存 html 文件,它也只保存代码。没有数据。我对java html编程一无所知。但是我阅读了许多相关问题,但找不到问题的答案。我在 Firefox 中使用了检查元素。它显示在调试器、bootstrap.js 和 jquery.js 和 list.html 中。我很感激任何帮助。

get(" http://laaablaaablaaablaaaab与我用来查看数据的 url 相似,但不完全相同。

提前致谢。

<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">&larr;</span> Older</a>
            </li>
            <li class="next"><a id="nxtpg" href="#">Newer <span aria-hidden="true">&rarr;</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];
    });

   `
4

1 回答 1

0

问题是该表是由 javascript 填充的,但您的函数不会评估 javascript,它只是拉入 HTML。查看http://phantomjs.org/以获取用 Javascript 编写的通用解决方案。如果使用 Phantom.js 命令行界面构建解决方案,您可以通过 system() 函数从 MATLAB 访问它。

于 2015-10-29T21:52:58.893 回答