Skip to content

Commit e7143f6

Browse files
committed
Add more tests
1 parent 5ed88e5 commit e7143f6

File tree

7 files changed

+45285
-14
lines changed

7 files changed

+45285
-14
lines changed
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1-
exports['works with product url 1'] = {
1+
exports['product url 1'] = {
2+
"author": "Mat Follas",
3+
"title": "Vegetable Perfection: 100 delicious recipes for roots, bulbs, shoots and stems",
4+
"publisher": "Amazon",
5+
"image": "https://images-eu.ssl-images-amazon.com/images/I/61Q2c36lYeL._SX218_BO1,204,203,200_QL40_.jpg",
6+
"date": "0178-10-02T12:00:00.000Z",
7+
"description": "Buy Vegetable Perfection: 100 delicious recipes for roots, bulbs, shoots and stems by Mat Follas (ISBN: 9781849757096) from Amazon’s Book Store. Everyday low prices and free delivery on eligible orders.",
8+
"logo": null,
9+
"url": "https://www.amazon.co.uk/Vegetable-Perfection-tasty-recipes-shoots/dp/1849757097/ref=asap_bc?ie=UTF8"
10+
}
11+
12+
exports['ansi url 1'] = {
213
"author": "SainSmart",
14+
"title": "SainSmart 4-Channel Relay Module",
15+
"publisher": "Amazon",
16+
"image": "https://images-na.ssl-images-amazon.com/images/I/51M0KK9HuHL._SY300_QL70_.jpg",
317
"date": "2017-12-20T12:00:00.000Z",
418
"description": "Buy SainSmart 4-Channel Relay Module: Everything Else - Amazon.com ✓ FREE DELIVERY possible on eligible purchases",
5-
"image": "https://images-na.ssl-images-amazon.com/images/I/51M0KK9HuHL._SY300_QL70_.jpg",
619
"logo": null,
7-
"publisher": "Amazon",
8-
"title": "SainSmart 4-Channel Relay Module",
920
"url": "https://www.amazon.com/gp/product/B0057OC5O8/"
1021
}
22+
23+
exports['product url 2'] = {
24+
"author": "David Baldacci",
25+
"title": "The Whole Truth (A. Shaw Book 1) Kindle Edition",
26+
"publisher": "Amazon",
27+
"image": "https://images-na.ssl-images-amazon.com/images/I/519trKzgiKL._SY346_.jpg",
28+
"date": "2018-04-30T12:00:00.000Z",
29+
"description": "The Whole Truth (A. Shaw Book 1) - Kindle edition by David Baldacci. Download it once and read it on your Kindle device, PC, phones or tablets. Use features like bookmarks, note taking and highlighting while reading The Whole Truth (A. Shaw Book 1).",
30+
"logo": null,
31+
"url": "https://www.amazon.com/The-Whole-Truth-Shaw-Book-ebook/dp/B0011UCPM4/ref=pd_zg_rss_ts_b_17_6?ie=UTF8&tag=recomshop-22"
32+
}
33+
34+
exports['product url 3'] = {
35+
"author": "Cecotec",
36+
"title": "Robot aspirador Conga Excellence 990 de Cecotec. Friega el suelo, Barre, aspira y pasa la mopa. Programable 24h. 5 modos de limpieza. Base de carga. Silencioso. Potente. Filtro HEPA.",
37+
"publisher": "Amazon",
38+
"image": "https://images-na.ssl-images-amazon.com/images/I/81lde%2B541vL._SL1500_.jpg",
39+
"date": "2017-12-20T01:00:00.000Z",
40+
"description": "Compra Robot aspirador Conga Excellence 990 de Cecotec. Friega el suelo, Barre, aspira y pasa la mopa. Programable 24h. 5 modos de limpieza. Base de carga. Silencioso. Potente. Filtro HEPA.. Precios bajos todos los días en Amazon.",
41+
"logo": null,
42+
"url": "https://www.amazon.es/aspirador-Excellence-Programable-limpieza-Silencioso/dp/B01MUGXRT9"
43+
}

packages/metascraper-amazon/index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { titleize } = require('@metascraper/helpers')
3+
const { titleize, isUrl } = require('@metascraper/helpers')
44

55
const REGEX_AMAZON_URL = /https?:\/\/(.*amazon\..*\/.*|.*amzn\.com\/.*)/i
66
const isAmazonUrl = url => REGEX_AMAZON_URL.test(url)
@@ -11,9 +11,27 @@ const wrap = rule => ({ htmlDom, url }) => {
1111
return value
1212
}
1313

14+
const wrapUrl = rule => ({ htmlDom, url }) => {
15+
const value = wrap(rule)({htmlDom, url})
16+
if (!isUrl(value)) return
17+
return value
18+
}
19+
1420
module.exports = () => ({
15-
author: [wrap($ => $('#bylineInfo').text())],
16-
title: [wrap($ => titleize($('#productTitle').text()))],
21+
author: [
22+
wrap($ => titleize($('.contributorNameID').text())),
23+
wrap($ => titleize($('#bylineInfo').text())),
24+
wrap($ => titleize($('#brand').text()))
25+
],
26+
title: [
27+
wrap($ => titleize($('#productTitle').text())),
28+
wrap($ => titleize($('#btAsinTitle').text())),
29+
wrap($ => titleize($('h1.a-size-large').first().text())),
30+
wrap($ => titleize($('#item_name').text()))
31+
],
1732
publisher: [wrap($ => 'Amazon')],
18-
image: [wrap($ => $('#landingImage').attr('src'))]
33+
image: [
34+
wrapUrl($ => $('.a-dynamic-image').attr('data-old-hires')),
35+
wrapUrl($ => $('.a-dynamic-image').attr('src'))
36+
]
1937
})

0 commit comments

Comments
 (0)