The function imgArray returns just one image and not an array. That is, the third column of the spreadsheet which is img lists just one image. Here is my code:
const rp = require('request-promise');
const otcsv = require('objects-to-csv');
const cheerio = require('cheerio');
const baseURL = 'https://www.example.com';
const getCategories = async () => {
const html = await rp(baseURL);
const imgArray = () => {
cheerio('td.productListing-data > a > img', html).each((i, image) => {
img = cheerio(image).attr('src');
})};
imgArray();
const businessMap = cheerio('.category', html).map(async (i, e) => {
const link = e.attribs.href;
const innerHtml = await rp(link);
const cat = e.children[0].data;
return {
link,
cat,
img,
}
}).get();
return Promise.all(businessMap);
};
getCategories()
.then(result => {
const transformed = new otcsv(result);
return transformed.toDisk('./spreadsheets/output.csv');
})
.then(() => console.log('SUCCESSFULLY COMPLETED THE WEB SCRAPING SAMPLE'));
!--removed tag-->
Enter your message below
Sign in or Join us (it's free).