node Cheerio 获取script脚本里的数据


const cheerio = require('cheerio');
const $ = cheerio.load(html); // your html
//如果有多少script脚本标签使用循环来获取
$('script').map(function(i, el) {
// 建议这里打印$(this) 因为this的对象可能不同
//因为存在script标签为空的数据, 所以判断children长度是否大于0
console.log("ffffffffff", $(this)[0].children[0])
//如果要获取script标签的属性, 例如 type
console.log($(this)[0].attribs['type'])
});
 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM