使用cheerio 转换以下代码 <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>
时间: 2024-02-13 14:06:14 浏览: 109
可以使用Cheerio将这段代码转换成一个数组,数组中包含了所有的span标签的文本内容。首先,需要安装Cheerio模块,可以在命令行中使用以下命令进行安装:
```
npm install cheerio
```
然后,在Node.js中可以使用以下代码将该代码段转换成一个数组:
```javascript
const cheerio = require('cheerio');
const html = '<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>';
const $ = cheerio.load(html);
const spans = $('td span');
const result = spans.toArray().map(span => span.firstChild.data.trim());
console.log(result);
```
运行后,将输出以下数组:
```json
["入账", "退汇", "待客户确认"]
```
注意,在这个例子中,我们首先使用Cheerio的$('td span')方法获取所有的span元素,然后使用toArray()方法将Cheerio对象转换成一个普通的JavaScript数组,最后使用map()方法获取每个span元素的文本内容并去除首尾空格,将结果保存为一个数组。
阅读全文
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
使用cheerio 将以下代码转换为json<html> <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)"> IR00252300347A IR00252300347A 2023-05-25 USD32,993.50 1/FLOKSER KIMYA SANAYI VE TICARET 1... 31980005000107125 入账 退汇 待客户确认 受理成功 打印 </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
cheerio 执行以下代码 <html> <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)"> IR00252300347A IR00252300347A 2023-05-25 USD32,993.50 1/FLOKSER KIMYA SANAYI VE TICARET 1... 31980005000107125 入账 退汇 待客户确认 受理成功 打印 </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
使用cheerio 将以下代码转换为json <html><head>123</head><body> <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)"> IR00252300347A IR00252300347A 2023-05-25 USD32,993.50 1/FLOKSER KIMYA SANAYI VE TICARET 1... 31980005000107125 入账 退汇 待客户确认 受理成功 打印 </body></html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)