UnhandledPromiseRejectionWarning: TypeError: $ is not a function

时间:2021-06-29 19:41:15

标签: javascript node.js windows visual-studio cmder

const $ = require ('cheerio');
const fetch = require('node-fetch');
const url = "https://fr.wikipedia.org/wiki/The_Legend_of_Zelda";


function extractionBrut(url){
    return fetch(url)
           .then((reponse) => reponse.text())
           .then((data) => {
               return data;
           })
}

const getFormationList = async () => {
    const data = await extractionBrut(url);

    const num = $.parseHTML(data).length;
    console.log(num);
    for(let i = 0; i<num; i++){
        const numTable = $('<div id="" class="bandeau-container homonymie plainlinks hatnote" style="">')[i];
        console.log(numTable);
    }
}
getFormationList();

我想显示这个 div 的不同部分,但是我有这个错误,不知道如何解决。

1 个答案:

答案 0 :(得分:0)

public function order() { $user_id = Session::get('name')['id']; $product = DB::table('cart') ->join('products', 'cart.product_id', '=', 'products.id') ->where('cart.user_id', $user_id) ->select('products.*') ->get(); return view('order-product') ->with('product', $product); } 应该加载数据。你会做这样的事情:

$

后来:

const cheerio = require ('cheerio');

现在您可以像使用 jQuery 一样使用 const $ = cheerio.load(someHtmlThatYouGotFromNodeFetch); ,或者cheerio 如何知道您正在使用什么 HTML?