使用cheerio将以下代码转换为json <table><!-- vRepeat: data in queryList --><tbody> <tr> <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></table>
时间: 2023-08-14 22:15:06 浏览: 107
好的,以下是使用cheerio将代码转换为json的示例代码:
```javascript
const cheerio = require('cheerio');
const html = '<table><!-- vRepeat: data in queryList --><tbody> <tr> <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></table>';
const $ = cheerio.load(html);
const data = [];
$('table tbody tr').each((i, el) => {
const obj = {};
obj['checkbox'] = $(el).find('input[type="checkbox"]').attr('name');
obj['link'] = $(el).find('a').text();
obj['date'] = $(el).find('td').eq(2).text();
obj['amount'] = $(el).find('td').eq(3).text();
obj['name'] = $(el).find('td').eq(4).text();
obj['account'] = $(el).find('td').eq(5).text();
obj['status'] = $(el).find('td').eq(6).text();
obj['result'] = $(el).find('td').eq(7).text();
obj['print'] = $(el).find('td').eq(8).text();
data.push(obj);
});
console.log(data);
```
输出结果为:
```
[
{
checkbox: 'RemitInBox',
link: 'IR00252300347A',
date: '2023-05-25',
amount: 'USD32,993.50',
name: '1/FLOKSER KIMYA SANAYI VE TICARET 1...',
account: '31980005000107125',
status: '入账',
result: '受理成功',
print: ' '
}
]
```
希望对您有帮助!
阅读全文