Setup scraping with css selectors

Hi folks,

I’m quite new to scraping and trying to set up an actor which is scraping different css selectors (e.g. div.a-row.a-carousel-controls.a-carousel-row > div > div > div > ol > li:nth-child(1) > div > div > div > div:nth-child(3) > span > span > span.a-truncate-full) from a list of URLs, e.g. https://www.amazon.com/s?k=lawn+mower!&ref=nb_sb_noss_2

While trying to start with the tutorial https://apify.com/docs/scraping/web-scraper-tutorial the page function

async function pageFunction(context) {
    const { request, log, skipLinks, jQuery: $ } = context; // Use jQuery as $
    if (request.userData.label === 'START') {
        log.info('Library opened!');
        // Do some stuff later.
    }
    if (request.userData.label === 'DETAIL') {
        const { url } = request; 
        log.info(`Scraping ${url}`);
        await skipLinks();

const $wrapper = $('search');
return {
    description: $wrapper.find('div.a-row.a-carousel-controls.a-carousel-row > div > div > div > ol > li:nth-child(1) > div > div > div > div:nth-child(3) > span > span > span.a-truncate-full').text(),
};
}
}

won’t return the description. Any idea where I can find a tutorial how to set this up?

Thanks a lot for your time and support!

Hi there,

your selector looks quite complicated, but I tested and it works.
But you don’t need to user const $wrapper = $('search');. I’m not sure why did you use it.
You can just return description like:

return {
    description: $('div.a-row.a-carousel-controls.a-carousel-row > div > div > div > ol > li:nth-child(1) > div > div > div > div:nth-child(3) > span > span > span.a-truncate-full').text(),
};