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