1
I’m making a web Rawler that should extract the name and price of iphones that appear in search on the Amazon site and generate an xlsx file with this data. However, I am unable to generate the xlsx file with this data.
I’m trying to do this through the excel4node module, but because of my little knowledge I’m having problems to fit the data into the spreadsheet.
var request = require('request-promise');
var cheerio = require('cheerio');
var excel = require('excel4node');
var wb = new excel.Workbook();
var ws = wb.addWorksheet('AMAZON');
var url = 'http://localhost:81/index.html';
var newEncode = encodeURI(url);
const crawl ={
uri: (newEncode),
transform: function (body){
return cheerio.load(body);
}
}
request(crawl)
.then(($) =>{
const produtos = []
$('div[class="sg-col-20-of-24 s-result-item sg-col-0-of-12 sg-col-28-of-32 sg-col-16-of-20 sg-col sg-col-32-of-36 sg-col-12-of-16 sg-col-24-of-28"]').each((i, item)=>{
const produto = {
nome: $(item).find('span[class="a-size-medium a-color-base a-text-normal"]').text(),
preco: $(item).find('span[class="a-price-whole"], span[class="a-price-fraction"], span[class="a-color-base"]').text(),
}
// console.log(item);
ws.cell().string(); //não sei quais parâmetros adicionar aqui
wb.write('PlanilhaAmazon.xlsx');
});
})
.catch((err) => {
console.log(err);
})
Is the data coming in correctly? I need to know before mounting an example
– Anderson Henrique
Yes, Anderson. The data is coming in correctly.
– Marcos Davi Spindola