Skip to content

Instantly share code, notes, and snippets.

@sr2ds
Last active April 15, 2019 20:10
Show Gist options
  • Save sr2ds/23d9ea54dc80539faef04f2eb3582a73 to your computer and use it in GitHub Desktop.
Save sr2ds/23d9ea54dc80539faef04f2eb3582a73 to your computer and use it in GitHub Desktop.
Initial Implement for scrapper aliexpress category with nodejs
const rp = require('request-promise');
const $ = require('cheerio');
const baseLink = `https://pt.aliexpress.com/category/`
const categoryPath = `201000005/home-appliances/`
const ApiGet = {
getMultiplePages(totalPages) {
for (let page = 1; page <= totalPages; page++) {
ApiGet.getByPageNumber(page)
}
},
getByPageNumber(pageNumber) {
const url = `${baseLink}${categoryPath}${pageNumber}.html`
const products = []
rp(url)
.then(function(html){
const items = $('li.list-item', html)
items.each(function(index,item) {
const link = $(item).find('.product').attr('href')
const title = $(item).find('.product').attr('title')
const total = Number($(item).find('em').text().replace('Pedidos', '').replace(')','').replace('(', ''))
const id = $(item).find('input.atc-product-id').val()
products.push({ id, title, link, total })
})
console.log(products.length)
})
}
}
ApiGet.getMultiplePages(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment