Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
tableasjson
Advanced tools
(Forked from https://github.com/iaincollins/tabletojson)
Attempts to convert HTML tables into JSON.
Can be passed the markup for a single table as a string, a fragment of HTML or an entire page or just a URL (with an optional callback function; promises also supported).
The response is always an array. Every array entry in the response represents a table found on the page (in same the order they were found in the HTML).
This module only supports parsing basic tables with a simple horizontal set of headings and corresponding cells.
It can give useless results on tables that have complex structures or multiple headers (such as on both X and Y axis).
You'll need to handle things like work out which tables to parse and (in most cases) clean up the data. You might want to combine it it with modules like json2csv.
You might want to use it with a module like 'cheerio' if you want to parse specific tables identified by id or class (i.e. select them with cheerio and pass the HTML of them as a string).
// Convert an HTML blob into an array of all the tables on the page
var tabletojson = require('tableasjson');
var tablesAsJson = tabletojson.convert(html);
var firstTableAsJson = tablesAsJson[0];
var secondTableAsJson = tablesAsJson[1];
...
// Fetch a URL and parse all it's tables into JSON, using a callback
var tabletojson = require('tableasjson');
var url = 'https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes';
tabletojson.convertUrl(url, function(tablesAsJson) {
var listofSovereignStates = tablesAsJson[0];
});
// Fetch a URL and parse all it's tables into JSON, using promises
var tabletojson = require('tableasjson');
var url = 'http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating';
tabletojson.convertUrl(url)
.then(function(tablesAsJson) {
var standardAndPoorRatings = tablesAsJson[0];
var fitchRatings = tablesAsJson[1];
});
// Fetch a table from Wikipedia and combine with json2csv to convert to CSV
var tabletojson = require('tableasjson');
var json2csv = require('json2csv');
var url = 'http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating';
tabletojson.convertUrl(url)
.then(function(tablesAsJson) {
var standardAndPoorCreditRatings = tablesAsJson[0];
json2csv({ data: standardAndPoorCreditRatings,
fields: [ 'Country', 'Outlook']
}, function(err, csv) {
console.log(csv);
/* Example output
"Country","Outlook"
"Abu Dhabi, UAE","Stable"
"Albania","Stable"
"Andorra","Negative"
"Angola","Stable"
"Argentina","Negative"
"Aruba","Stable"
"Australia","Stable"
"Austria","Negative"
"Azerbaijan","Positive"
...
*/
});
});
Improvements, fixes and suggestions for better written modules that other people have created are welcome, as are bug reports against specific tables it is unable to handle.
FAQs
Converts HTML tables to JSON objects (Fork of tabletojson)
The npm package tableasjson receives a total of 0 weekly downloads. As such, tableasjson popularity was classified as not popular.
We found that tableasjson demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.