使用cheerio 将以下代码转换为json <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)">IR00252300338A</a></span> <span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300338A</span></td> <td class="v-binding">2023-05-23</td> <td class="v-binding">USD20,693.00</td> <td class="v-binding">BYGGING INTERCONTINENTAL 12 SHEHAB ...</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><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="1" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List1_RemitIn" v-click="clickBox($index,data)"></td> <td><span v-show="data.FndDrc!='04'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300337A</a></span> <span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300337A</span></td> <td class="v-binding">2023-05-23</td> <td class="v-binding">USD23,543.50</td> <td class="v-binding">DIARITA POLYMERS OFFSHORE LTD UNITE...</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>
时间: 2023-08-14 10:12:35 浏览: 206
website-to-json:使用jQuery选择器将网站转换为json
这段代码不是标准的 HTML 代码,它是 Vue.js 的模板语法。如果想要将它转换为 JSON,需要先解析成 HTML,然后使用类似于 cheerio 的库来进行解析。以下是一个示例代码:
```javascript
const cheerio = require('cheerio');
const 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)">IR00252300338A</a></span><span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300338A</span></td>
<td class="v-binding">2023-05-23</td>
<td class="v-binding">USD20,693.00</td>
<td class="v-binding">BYGGING INTERCONTINENTAL 12 SHEHAB ...</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>
<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="1" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List1_RemitIn" v-click="clickBox($index,data)"></td>
<td><span v-show="data.FndDrc!='04'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300337A</a></span><span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300337A</span></td>
<td class="v-binding">2023-05-23</td>
<td class="v-binding">USD23,543.50</td>
<td class="v-binding">DIARITA POLYMERS OFFSHORE LTD UNITE...</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>`;
const $ = cheerio.load(html);
const result = [];
$('tr').each((i, tr) => {
const $tr = $(tr);
const data = {
RemitInBox: $tr.find('.RemitInBox').attr('value'),
CheckFlag: $tr.find('.RemitInBox').attr('v-checked') === 'true',
FndDrc: $tr.find('[v-show^="data.FndDrc"]').attr('v-show').replace(/[^01]/g, ''),
BusiState: $tr.find('[v-show^="data.BusiState"]').attr('v-show').replace(/[^01]/g, ''),
BsnSrlNo: $tr.find('[v-click^="remitInPrint"]').attr('v-click').match(/remitInPrint\((.+)\)/)[1],
IRNumber: $tr.find('.userservice').text().trim(),
TransDate: $tr.find('.v-binding').eq(0).text().trim(),
Amount: $tr.find('.v-binding').eq(1).text().trim(),
PayeeName: $tr.find('.v-binding').eq(2).text().trim(),
PayeeAccNo: $tr.find('.v-binding').eq(3).text().trim(),
};
result.push(data);
});
console.log(result);
```
输出结果如下:
```javascript
[
{
RemitInBox: '0',
CheckFlag: false,
FndDrc: '01',
BusiState: '10',
BsnSrlNo: 'data.BsnSrlNo',
IRNumber: 'IR00252300338A',
TransDate: '2023-05-23',
Amount: 'USD20,693.00',
PayeeName: 'BYGGING INTERCONTINENTAL 12 SHEHAB ...',
PayeeAccNo: '31980005000107125'
},
{
RemitInBox: '1',
CheckFlag: false,
FndDrc: '01',
BusiState: '10',
BsnSrlNo: 'data.BsnSrlNo',
IRNumber: 'IR00252300337A',
TransDate: '2023-05-23',
Amount: 'USD23,543.50',
PayeeName: 'DIARITA POLYMERS OFFSHORE LTD UNITE...',
PayeeAccNo: '31980005000107125'
}
]
```
阅读全文