Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
tabletojson
Advanced tools
Converts HTML tables to JSON. Can be passed an HTML blob or URL.
Can be passed the markup for a single table, a fragment of HTML or an entire page or a URL (with an optional callback function - also supports promises).
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).
I wrote this because I've been doing a lot of HTML scraping on hack days recently.
It only supports parsing basic tables with a simple horizontal set of headings and corresponding cells.
It's intended for hackers, you'll need to handle things like work out which tables to parse and (in most cases) to 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 only ever parse specific tables in a blob of HTML.
// Convert an HTML blob into an array of all the tables on the page
var tabletojson = require('tabletojson');
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('tabletojson');
var url = 'http://en.wikipedia.org/wiki/List_of_sovereign_states';
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('tabletojson');
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('tabletojson');
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"
...
*/
});
});
FAQs
Convert HTML tables to JSON objects
The npm package tabletojson receives a total of 8,792 weekly downloads. As such, tabletojson popularity was classified as popular.
We found that tabletojson demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.