drawrowfly / amazon-product-api

Amazon Scraper. Scrape products from the amazon search result or reviews from the specific product
624 stars 178 forks source link

Please...cant scrape color name and size name from amazon.es #120

Open mkudev opened 10 months ago

mkudev commented 10 months ago

I created it, but not working, rest of script work fine, I need scrap asin details of color and size names, text plain to easy csv import to woocommece. I hope you help bro.

const fs = require('fs').promises; const amazonScraper = require('amazon-buddy'); const createCsvWriter = require('csv-writer').createObjectCsvWriter;

(async () => { try { const asinList = await fs.readFile('asin-list.txt', 'utf-8'); const asinArray = asinList.trim().split('\n');

    const productsData = await amazonScraper.asin({
        asin: asinArray,
        country: 'ES',
        category: 'moda',
        limit: 13,
        filetype: 'csv'
    });

    for (const product of productsData) {
        product.variation_color_name = ''; // Agrega esto para evitar el error en caso de que no se encuentre la propiedad
        const sizeOptions = $('#native_dropdown_selected_size_name option[value!="0,B01M1C6RFY"]').map((index, element) => {
            const value = $(element).attr('value');
            const size = $(element).text().trim();
            return { value, size };
        }).get();

        product.size_options = sizeOptions;
    }

    const csvWriter = createCsvWriter({
        path: 'output.csv',
        header: [
            { id: 'asin', title: 'ASIN' },
            { id: 'url', title: 'URL' },
            { id: 'product', title: 'Producto' },
            { id: 'variation_color_name', title: 'Nombre de Color' },
            // ... (otros encabezados)
            { id: 'size_options', title: 'Opciones de Tamaño' },
            { id: 'variants', title: 'Variantes' },
            // ... (otros encabezados)
        ]
    });

    await csvWriter.writeRecords(productsData);

    console.log('Archivo CSV ha sido creado exitosamente.');
} catch (fileError) {
    console.log('Error al leer asin-list.txt:', fileError);
}

})();