实时数据提取JSON

时间:2016-02-12 11:32:09

标签: javascript jquery json

我编写了一个从网页中提取特定表格的代码。该网站是动态的,它每半小时更新一次表中的值。我的用于解析网站的Javascript每30分钟重新加载一次网站。但是作为JSON提取的数据只是特定时间的数据。但是,我希望每次网站重新加载时附加或连接所有数据(即,我需要与先前列表连接的当前数据列表,只要程序正在运行)我该怎么做?

网页为:https://www.emcsg.com/marketdata/priceinformation

所需表格是:查看72个期间

我的代码如下:

<html>
<head>
<title>Pricing </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script>
<meta http-equiv="refresh" content="1800" /><!--Reloads page every 30 minutes-->
<script>

      function requestCrossDomain(site, callback) {
          if (!site) {
              alert('No site was passed.');
              return false;
          }
          var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml&callback=?';
          $.getJSON(yql, cbFunc);
          function cbFunc(data) {
              if (data.results[0]) {
                  data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
                      window[callback](data);
              } else throw new Error('Nothing returned from getJSON.');
          }
      }

    var url = 'https://www.emcsg.com/marketdata/priceinformation';
    requestCrossDomain(url, 'someFunction');

    function someFunction(results){
        var html = $(results);
        var table = html.find(".view72PeriodsWrapper");
        $('#loadedContent').css("display","").html(table);

    }
</script>
</head>
<body>
<br><br>
<div id="result"></div>
<div id="loadedContent"></div>
</body>
</html>

0 个答案:

没有答案