如何控制台记录 html 元素内的文本?

How do I console log the text inside of html element?

我想在 https://www.bestbuy.com/site/jingle-all-the-way-family-fun-edition-dvd-1996/8538512.p?skuId=8538512 上控制台记录文本“Jingle All the Way [家庭娱乐版] [DVD] [1996]”。 我正在使用 axios , cheerio.

(async () =>{
   const { data } = await axios.get(productUrl);
   const $ = cheerio.load(data)
   const title = $('h1')[0];
   console.log(title)
   
})();

如果你能帮助我,请告诉我。这应该很简单,但我找不到答案。

尝试

(async () =>{
   const { data } = await axios.get(productUrl);
   const $ = cheerio.load(data)
   const title = $('h1');
   console.log(title.text());
   
})();

尝试将第 3 行更改为 const $ = await cheerio.load(data)