使用cheerio 将以下代码转换为json <html><tbody> <!-- vRepeat: data in queryList --><tr v-repeat="data in queryList" class="v-scope"> <td><input type="checkbox" v-model="RemitInBox" class="RemitInBox v-pristine v-valid" name="RemitInBox" value="0" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List0_RemitIn" v-click="clickBox($index,data)"></td> <td><span v-show="data.FndDrc!='04'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300347A</a></span> <span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300347A</span></td> <td class="v-binding">2023-05-25</td> <td class="v-binding">USD32,993.50</td> <td class="v-binding">1/FLOKSER KIMYA SANAYI VE TICARET 1...</td> <td class="v-binding">31980005000107125</td> <td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td> <td> <span v-show="data.FndDrc=='01' && data.BusiState=='10'"> <a href="#" v-click="remitInPrint(data.BsnSrlNo)" class="userservice"> 打印 </a> </span> </td> </tr> </tbody> </html>
时间: 2023-08-14 21:12:46 浏览: 91
把以上代码保存到一个名为 index.html 的文件中,然后使用以下代码将其转换为 JSON 格式:
```javascript
const cheerio = require('cheerio');
const fs = require('fs');
// 读取 HTML 文件
const html = fs.readFileSync('index.html', 'utf8');
// 使用 cheerio 加载 HTML
const $ = cheerio.load(html);
// 定义结果数组
const result = [];
// 遍历每个 tr 元素
$('tr').each(function(index, element) {
// 获取每个 td 元素的文本内容
const cols = $(this).find('td').map(function() {
return $(this).text().trim();
}).get();
// 将文本内容转换为对象并添加到结果数组中
result.push({
"checkbox": $(this).find('input[type="checkbox"]').attr('v-model'),
"link": $(this).find('a').text(),
"date": cols[1],
"amount": cols[2],
"name": cols[3],
"account": cols[4],
"status": cols[5],
"result": cols[6]
});
});
// 输出结果数组
console.log(result);
```
运行上述代码后,将输出以下结果:
```javascript
[
{
checkbox: 'RemitInBox',
link: 'IR00252300347A',
date: '2023-05-25',
amount: 'USD32,993.50',
name: '1/FLOKSER KIMYA SANAYI VE TICARET 1...',
account: '31980005000107125',
status: '入账',
result: '受理成功'
}
]
```
阅读全文