ripe-grayR
Apify & Crawlee4y ago
1 reply
ripe-gray

How to create a new cheerio instance $?

I need to instatiate a new cheerio object, i'm doing a search in a set o elements and need to select just one element for further processing, my actual code is:
function getOrigin($: typeof cheerioModule) {
    let origin = ""
    const specElements = $('#product_specs table tr').toArray()
    for (const spec of specElements) {
        const _$ = cheerioModule.load(spec)
        const specTitle = _$(".attrib").text().trim()
        if(specTitle.includes("제조국")){
            origin = _$(".attrib-val").text().trim()
            break
        }
    }
    return origin
}

but i'm not sure if that is the right way to instantiate a new cheeio object in crawlee.
Was this page helpful?