This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathselectors.js
144 lines (135 loc) · 4.17 KB
/
selectors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import {parsePrice} from 'commerce/extraction/utils';
function inUnits(fn) {
return (element) => {
let tokens = fn(element);
if (!Array.isArray(tokens)) {
tokens = [tokens];
}
return parsePrice(tokens);
};
}
function fromChildrenText() {
return (element => Array.from(element.childNodes).map(node => node.textContent));
}
function fromProperty(property) {
return (element => element[property]);
}
function fromAttribute(attribute) {
return (element => element.getAttribute(attribute));
}
/**
* CSS selector data by site, where each selector is paired with a method that
* extracts the value from the element returned by that selector.
*/
const fallbackExtractionData = [
{
domains: ['amazon.com', 'www.amazon.com', 'smile.amazon.com'],
features: {
title: [
['#productTitle', fromProperty('innerText')],
['.product-title', fromProperty('innerText')],
],
price: [
['#priceblock_dealprice', inUnits(fromChildrenText())],
['#priceblock_ourprice', inUnits(fromChildrenText())],
['#price_inside_buybox', inUnits(fromChildrenText())],
['#buybox .a-color-price', inUnits(fromChildrenText())],
['input[name="displayedPrice"]', inUnits(fromAttribute('value'))],
['.a-size-large.a-color-price.guild_priceblock_ourprice', inUnits(fromChildrenText())],
['.a-color-price.a-size-medium.a-align-bottom', inUnits(fromChildrenText())],
['.display-price', inUnits(fromChildrenText())],
['.offer-price', inUnits(fromChildrenText())],
],
image: [
['#landingImage', fromProperty('src')],
['#imgBlkFront', fromProperty('src')],
['#ebooksImgBlkFront', fromProperty('src')],
['#main-image-container img', fromProperty('src')],
],
},
},
{
domains: ['bestbuy.com', 'www.bestbuy.com'],
features: {
title: [
['.sku-title h1', fromProperty('innerText')],
],
price: [
['.priceView-hero-price.priceView-purchase-price', inUnits(fromChildrenText())],
],
image: [
['img.primary-image', fromProperty('src')],
],
},
},
{
domains: ['ebay.com', 'www.ebay.com'],
features: {
title: [
['#itemTitle', fromProperty('innerText')],
['.product-title', fromProperty('innerText')],
],
price: [
['#prcIsum', inUnits(fromChildrenText())],
['#orgPrc', inUnits(fromChildrenText())],
['#mm-saleDscPrc', inUnits(fromChildrenText())],
['.display-price', inUnits(fromChildrenText())],
],
image: [
['#icImg', fromProperty('src')],
['.vi-image-gallery__image.vi-image-gallery__image--absolute-center', fromProperty('src')],
],
},
},
{
domains: ['homedepot.com', 'www.homedepot.com'],
features: {
title: [
['h1.product-title__title', fromProperty('innerText')],
],
price: [
['#ajaxPrice', inUnits(fromAttribute('content'))],
['#ajaxPriceAlt', inUnits(fromChildrenText())],
],
image: [
['#mainImage', fromProperty('src')],
],
},
},
{
domains: ['walmart.com', 'www.walmart.com'],
features: {
title: [
['h1.prod-ProductTitle', fromAttribute('content')],
['h1.prod-ProductTitle', fromProperty('innerText')],
],
price: [
['.PriceRange.prod-PriceHero', inUnits(fromChildrenText())],
['.price-group', inUnits(fromAttribute('aria-label'))],
['.price-group', inUnits(fromChildrenText())],
],
image: [
['.prod-hero-image-image', fromProperty('src')],
['.prod-hero-image-carousel-image', fromProperty('src')],
],
},
},
{
domains: ['mozilla.github.io'],
features: {
title: [
['#title', fromProperty('innerText')],
],
price: [
['#price', inUnits(fromChildrenText())],
],
image: [
['img', fromProperty('src')],
],
},
},
];
export default fallbackExtractionData;