使用cheerio 将以下代码转换为json <html><body><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> </body></html>
时间: 2023-08-14 18:12:46 浏览: 103
website-to-json:使用jQuery选择器将网站转换为json
抱歉,这段HTML代码不够完整,缺少一些标签和属性。但是,我可以给你一个思路,你可以根据你的实际代码进行修改。
首先,你需要使用`cheerio`模块将HTML代码转换为DOM对象,然后使用DOM操作获取到需要的数据。在这个例子中,我们需要获取到每个`<tr>`元素中的数据,包括`v-repeat`、`v-checked`、`v-disabled`、`v-click`等属性,以及每个`<td>`元素中的文本内容。
接下来,我们可以将这些数据存储在一个数组中,并使用`JSON.stringify()`方法将其转换为JSON格式的字符串。最终的代码可能类似于下面这样:
```javascript
const cheerio = require('cheerio');
const html = '<html><body><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> </body></html>';
const $ = cheerio.load(html);
const dataArr = [];
$('tr').each((i, elem) => {
const data = {};
const $tr = $(elem);
data.vRepeat = $tr.attr('v-repeat');
data.vChecked = $tr.find('input').attr('v-checked');
data.vDisabled = $tr.find('input').attr('v-disabled');
data.vClick = $tr.find('input').attr('v-click');
data.text1 = $tr.find('td:eq(0)').text();
data.text2 = $tr.find('td:eq(1)').text();
data.text3 = $tr.find('td:eq(2)').text();
data.text4 = $tr.find('td:eq(3)').text();
data.text5 = $tr.find('td:eq(4)').text();
data.text6 = $tr.find('td:eq(5)').text();
data.text7 = $tr.find('td:eq(6)').text();
data.text8 = $tr.find('td:eq(7)').text();
dataArr.push(data);
});
const json = JSON.stringify(dataArr);
console.log(json);
```
阅读全文