How to use tabletojson - 10 common examples

To help you get started, we’ve selected a few tabletojson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github misterGF / echo / src / echo-table-2-file.js View on Github external
function _prepareHTML (html, options) {
  var tables = ''
  var tableIds = []
  var $ = cheerio.load(html)

  // Check if we should filter down based on ID.
  var filter = (typeof options.tableId !== 'undefined') ? '#' + options.tableId : 'table'

  // Try to grab each table using cheerio to get an ID for the filename. Filter HTML down to wanted tables.
  $(filter).each(function (i, element) {
    tableIds[i] = $(this).attr('id')
    tables += $(this).parent().html()
  })

  var tablesAsJson = tabletojson.convert(tables)

  var status = (tablesAsJson.length === 1) ? 'Found 1 table.' : ('Found ' + tablesAsJson.length + ' tables.')
  console.log((status).data)

  _writeData(tablesAsJson, tableIds, options)
}
github atheed / CricAPI / api / server.js View on Github external
var $ = cheerio.load(html);
            var name;
            var json = {name: ""};
            // get player's name
            $('.SubnavSubsection').filter(function() {
                var data = $(this);
                name = data.text();
                json.name = name;
            });

            var stats = $('.engineTable');

            numFormats = tabletojson.convert($(stats))[1].length;

            for (var i = 0; i < numFormats; i++) {
                var bowling = tabletojson.convert($(stats))[1][i];
                var format = bowling['0'];
                delete bowling['0'];
                if(format === "Tests") {
                    json.tests = bowling;
                } else if(format === "ODIs") {
                    json.ODIs = bowling;
                } else if(format === "T20Is") {
                    json.T20Is = bowling;
                } else if(format === "First-class") {
                    json.firstClass = bowling;
                } else if(format === "List A") {
                    json.listA = bowling;
                } else if(format === "Twenty20") {
                    json.twenty20 = bowling;
                } else {
                    break;
github atheed / CricAPI / server.js View on Github external
request(url, function(error, response, html) {
        if(!error) {
            var $ = cheerio.load(html);
            var name;
            var json = {name: ""};
            // get player's name
            $('.SubnavSubsection').filter(function() {
                var data = $(this);
                name = data.text();
                json.name = name;
            });

            var stats = $('.engineTable');

            // test stats
            var testBatting = tabletojson.convert($(stats))[0][0];
            delete testBatting['0'];
            json.tests = testBatting;

            // ODI stats
            var odiBatting = tabletojson.convert($(stats))[0][1];
            delete odiBatting['0'];
            json.ODIs = odiBatting;

            // T20I stats
            var t20IBatting = tabletojson.convert($(stats))[0][2];
            delete t20IBatting['0'];
            json.T20Is = t20IBatting;

            // first-class stats
            var fcBatting = tabletojson.convert($(stats))[0][3];
            delete fcBatting['0'];
github pablote / fs-mgmt / src / js / services / freeswitch / parsers / CallListParser.js View on Github external
return $q(function(resolve, reject) {
                    var response = [];

                    // parse html table in response into json object
                    var $ = cheerio.load(fsTextResponse);
                    var tableHtml = $('table').html();

                    if (S(tableHtml).isEmpty()) {
                        resolve(response);
                    } else {
                        var tableAsJson = tabletojson.convert('' + tableHtml + '<table></table>');

                        // iterate results
                        for (var i = 0; i &lt; tableAsJson[0].length; i++) {
                            if (tableAsJson[0].hasOwnProperty(i)) {
                                var row = tableAsJson[0][i];

                                // ignore row 0 which is the header row
                                if (i &gt; 0) {
                                    // build call based on row
                                    response.push(new Call(row));
                                }
                            }
                        }

                        resolve(response);
                    }
github patrickjquinn / P-Brain.ai / skills / fact / google / index.js View on Github external
xray(tablehtml, ['table@html'])((conversionError, tableHtmlList) =&gt; {
            if (tableHtmlList) {
                // xray returns the html inside each table tag, and tabletojson
                // expects a valid html table, so we need to re-wrap the table.
                const table1 = tabletojson.convert('' + tableHtmlList[0] + '<table></table>')

                let csv = json2csv({
                    data: table1,
                    hasCSVColumnTitle: false
                })

                csv = csv.replace(/(['"])/g, '')
                csv = csv.replace(/\,(.*?)\:/g, ', ')
                csv = csv.replace(/\{(.*?)\:/g, ', ')

                found = csv.toString()
            }
        })
    }
github maxthyen / table-scraper / index.js View on Github external
resolve(tableHtmlList.map(function(table) {
          // xray returns the html inside each table tag, and tabletojson
          // expects a valid html table, so we need to re-wrap the table.
          // Returning the first element in the converted array because
          // we should only ever be parsing one table at a time within this map.
          return tabletojson.convert('' + table + '<table></table>')[0];
        }));
      });
github rajatdhoot123 / indian-courier-api / api / bluedart.js View on Github external
}, function (err, res, body) {
        if(tabletojson.convert(body)[6][0][0] === "Status and Scans"){
        let final = tabletojson.convert(body)[6].reduce((acc, current, index) => {
            if(index > 2){
                return [...acc, { location: current['0'], detail: current['1'], date: `${current['2']} ${current['3']}` }]
            }
            return acc;
        },[]);
        final.splice(-2)
        response.json({
            result: final
        }) 
        } else {
            response.json({
                error: `Invalid Tracking Id ${tracking}`
            })
        }
    })
github BlueSCar / ncaa-stats / app / services / statistics.service.js View on Github external
var createTeamData = function (body) {
    var data = {
        teams: []
    };

    var teamRegExp = /^(.+) \((.+)\)$/;
    var $ = cheerio.load(body);

    tabletojson.convert(body)[1].forEach(function (item) {
        var match = teamRegExp.exec(item.Team);

        if (match) {
            item.Team = match[1];
            item.Conference = match[2];

            data.teams.push(item);
        }
    });

    return data;
};
github ipanardian / cekresi-cli / index.js View on Github external
parse() {
		if (this.checkResult()) {
			this.tablesAsJson = tabletojson.convert(this.result)
			print('\n==================== '+ this.infoExpedisi.yellow +' =========================\n')
			this.parseDeliveryInfo()
			print('')
			this.parseActivityInfo()
		}
		else {
			print('\nMaaf no resi yang anda masukkan sementara tidak dapat kami proses'.yellow)
		}
		print('\nFor details: https://github.com/ipanardian/cekresi-cli')
	}
}
github rajatdhoot123 / indian-courier-api / api / ekart.js View on Github external
router.get('/:awb', (req, res) => {
    let trackingId = req.params.awb
    tabletojson.convertUrl(url + trackingId)
        .then(tablesAsJson => {
            if (!tablesAsJson || !tablesAsJson.length){
                return res.json({ result: `Invalid Tracking Id ${trackingId}` })
            } else {
                let modified = tablesAsJson[1].reduce((acc, current) => [...acc, { location: current.Place, detail: current.Status, date: `${current.Date} ${current.Time}` }], [])
                return res.json({ result: modified })
            }
        }
    )
})

tabletojson

Convert HTML tables to JSON objects

MIT
Latest version published 16 days ago

Package Health Score

72 / 100
Full package analysis

Popular tabletojson functions