amazon-buddy
Advanced tools
Comparing version 2.2.4 to 2.2.5
@@ -955,2 +955,7 @@ // @ts-nocheck | ||
const book_in_series = this.extractBookInSeries($); | ||
if (book_in_series.length) { | ||
output.book_in_series = book_in_series; | ||
} | ||
output.other_sellers = this.extractOtherSellers($); | ||
@@ -1356,4 +1361,80 @@ | ||
} | ||
/** | ||
* Extract book series (if available) | ||
* @param {*} $ | ||
*/ | ||
extractBookInSeries($) { | ||
const series = []; | ||
const booksInTheSeries = $( | ||
'div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1)', | ||
)[0]; | ||
if (booksInTheSeries && booksInTheSeries.children) { | ||
booksInTheSeries.children.forEach((item, index) => { | ||
try { | ||
index += 1; | ||
const reviews = { | ||
total_reviews: 0, | ||
rating: 0, | ||
}; | ||
const price = { | ||
symbol: this.geo.symbol, | ||
currency: this.geo.currency, | ||
current_price: 0, | ||
}; | ||
const serie = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1) > span:nth-child(1)`, | ||
).text(); | ||
const image = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1) > img:nth-child(2)`, | ||
)[0].attribs.src; | ||
const url = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > a:nth-child(1)`, | ||
)[0].attribs.href; | ||
const title = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > a:nth-child(2) > span:nth-child(1)`, | ||
).text(); | ||
const total_reviews = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > span:nth-child(1) > a:nth-child(1) > span:nth-child(2)`, | ||
).text(); | ||
const rating = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > span:nth-child(1) > a:nth-child(1) > i:nth-child(1) > span:nth-child(1)`, | ||
)[0] | ||
? $( | ||
$( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > span:nth-child(1) > a:nth-child(1) > i:nth-child(1) > span:nth-child(1)`, | ||
)[0], | ||
) | ||
.text() | ||
.split(/\s/g)[0] | ||
: 0; | ||
reviews.total_reviews = parseInt(total_reviews.replace(/[^\d]/g, ''), 10); | ||
reviews.rating = rating; | ||
const current_price = $( | ||
`div.a-carousel-controls:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ol:nth-child(1) > li:nth-child(${index}) > div:nth-child(1) > div:nth-child(5)`, | ||
).text(); | ||
price.current_price = this.geo.price_format(current_price); | ||
series.push({ | ||
serie, | ||
title, | ||
images: [image], | ||
url: `${this.mainHost}${url}`, | ||
reviews, | ||
price, | ||
}); | ||
} catch { | ||
// continue regardless of error | ||
} | ||
}); | ||
} | ||
return series; | ||
} | ||
} | ||
module.exports = AmazonScraper; |
{ | ||
"name": "amazon-buddy", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Amazon Scraper. You can scrape products from amazon search result and you can also scrape reviews from a specific product", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
151263
2359