[英]I don't understand how to use cheerio class selectors
I want to get the children inside this element from within the website, and the elements inside the children我想从网站内获取此元素内的子元素,以及子元素内的元素
Code:代码:
const axios = require("axios");
const cheerio = require("cheerio");
(async () => {
const response = await axios.get(`...`);
const $ = cheerio.load(response.data);
let ChatBody = $('div[class="chatbody overflow-y-auto flex-column"]').children()
console.log(ChatBody)
/*ChatBody.each( (index, element) => {
console.log(index,element)
})*/
})();
Code and Output screenshot代码和输出截图
I use nodejs v12.22.10, axios and cheerio packages, javascript*我使用 nodejs v12.22.10、axios 和cheerio 包、javascript*
Maybe you want something like:也许你想要类似的东西:
$('.chatbody > *').get().map(el => $(el).text())
This will give text of all children这将给出所有孩子的文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.