forked from NikolaiT/scrapeulous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_amazon_wh.js
113 lines (91 loc) · 3.79 KB
/
check_amazon_wh.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
/**
* Scrape Amazon Product Data.
*
* Example Product: https://www.amazon.de/Sony-Systemkamera-Megapixel-LCD-Display-SEL-P1650/dp/B00IE9XHE0/ref=zg_bs_760674_1?_encoding=UTF8&psc=1&refRID=FE9P3C0J3R5XRR0KMP5E
*
* Price: 11,99 €
* Unverb. Preisempf
* Vendor
* Vendor Link
* customer reviews
*
* New and Used Link: https://www.amazon.de/gp/offer-listing/B00IE9XHE0/ref=dp_olp_all_mbc?ie=UTF8&condition=all
*
* On this new/used link, extract all amazon warehouse deals:
*
* Extract used status, price and description of used state
*
* @param product_link: The product_link leading to the amazon product
* @param options: Holds all configuration data and options
*/
async function Worker(product_link, options) {
await page.goto(product_link, {waitUntil: 'networkidle0'});
try {
await page.waitForSelector('#olp-upd-new-used-freeshipping', {
timeout: 15000
});
} catch (e) {
return 'no new/used products';
}
// extract product information
let product_data = await page.evaluate(() => {
const data = {
amazon_price: null,
rrp: null, // unverbindliche preisempfehlung
vendor: null,
vendor_link: null,
customer_reviews: null,
new_used_products_link: null
};
try {
data.amazon_price = document.getElementById('priceblock_ourprice').textContent;
data.rrp = document.querySelector('.priceBlockStrikePriceString').textContent;
data.vendor = document.getElementById('bylineInfo').textContent;
data.vendor_link = document.getElementById('bylineInfo').getAttribute('href');
data.customer_reviews = document.getElementById('averageCustomerReviews').innerText;
} catch (e) {
}
try {
data.new_used_products_link = document.querySelector('#olp-upd-new-used-freeshipping a').getAttribute('href');
// get a absolute url, just in case
if (data.new_used_products_link) {
data.new_used_products_link = document.location.origin + data.new_used_products_link;
}
} catch (e) {
console.error(e);
}
return data;
});
console.log(product_data.new_used_products_link);
// get the warehouse deals, only visit the first page actually
if (product_data.new_used_products_link) {
await page.goto(product_data.new_used_products_link, {waitUntil: 'networkidle0'});
await page.waitForSelector('#olpOfferListColumn');
await page.waitFor(500);
product_data.warehouse_deals = await page.evaluate(() => {
let deals = [];
document.querySelectorAll('#olpOfferList .a-row').forEach((node) => {
let img = node.querySelector('.olpSellerColumn a img');
let is_wh = img && img.getAttribute('alt') === 'Amazon Warehouse';
if (is_wh) {
let deal = {
warehouse_price: null,
prime: null, // unverbindliche preisempfehlung
state: null,
state_description: null,
};
try {
deal.warehouse_price = node.querySelector('.olpPriceColumn').innerText;
deal.prime = node.querySelector('.olpPriceColumn .a-icon-prime') !== null;
deal.state = node.querySelector('.olpConditionColumn .olpCondition').innerText;
deal.state_description = node.querySelector('.olpConditionColumn .comments').innerText;
} catch (e) {
}
deals.push(deal);
}
});
return deals;
});
}
return product_data;
}