Html 使用node.js将表转换为JSON
我正在尝试将表转换为JSON,以便轻松搜索数据,URL为: 我发现这个包裹: 我试着像这样使用它:Html 使用node.js将表转换为JSON,html,json,node.js,Html,Json,Node.js,我正在尝试将表转换为JSON,以便轻松搜索数据,URL为: 我发现这个包裹: 我试着像这样使用它: 'use strict'; const tabletojson = require('tabletojson'); tabletojson.convertUrl( 'http://www.tppcrpg.net/rarity.html', { useFirstRowForHeadings: true },
'use strict';
const tabletojson = require('tabletojson');
tabletojson.convertUrl(
'http://www.tppcrpg.net/rarity.html',
{ useFirstRowForHeadings: true },
function(tablesAsJson) {
console.log(tablesAsJson[1]);
}
);
但是它在控制台中返回undefined(未定义),是否有其他选项,或者我是否使用了错误的包?如果您实际正在获取数据,请更改console.log 您的输出总共只有一个数组,但您正在控制台中放置TableAsJSON[1],但数组索引以[0]开头
'use strict';
const tabletojson = require('tabletojson');
tabletojson.convertUrl(
'http://www.tppcrpg.net/rarity.html',
function(tablesAsJson) {
console.log(tablesAsJson[0]);
}
);
要获得外观更好的代码:
const url = 'http://www.tppcrpg.net/rarity.html';
tabletojson.convertUrl(url)
.then((data) => {
console.log(data[0]);
})
.catch((err) => {
console.log('err', err);
}); // to catch error
你想转换这个远程url吗?是的,我想获取JSON格式的数据,因为我不知道如何从表格式的行中获取数据。tppcrg url是你的吗?不,不是我的。你无法访问第三方api的数据,但是你想要那个数据,所以你正在尝试这个,对吗?谢谢,为我工作