-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
49 lines (27 loc) · 954 Bytes
/
example.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
'use strict'
let Traverse = require('./index');
let scraper = new Traverse();
scraper.on('scrape:product', ($, scraper, entry, options) => {
// GET THE DATA.
let title = $('#productTitle').text().trim();
console.log('');
console.log(`Product: ${title}`);
console.log('');
// Queue the other product links for scraping.
//// Find the product links.
let products = $('#sponsored-products-dp_feature_div li.a-carousel-card .sp_dpOffer > a');
console.log(`--- Found ${products.length} more products.`);
//// Push the links to the queue.
products.each((i, product) => {
let url = 'https://www.amazon.com' + $(product).attr('href');
scraper.push({
url: url,
tag: 'product'
});
});
});
scraper.push({
url: 'https://www.amazon.com/AmazonBasics-Apple-Certified-Lightning-Cable/dp/B010S9N6OO/',
tag: 'product'
});
scraper.start();