-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape-reviews.js
More file actions
27 lines (22 loc) · 806 Bytes
/
scrape-reviews.js
File metadata and controls
27 lines (22 loc) · 806 Bytes
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
// Example: Scrape Amazon Product Reviews
const { CrawlingAPI } = require('crawlbase'),
api = new CrawlingAPI({ token: 'CRAWLBASE_JS_TOKEN' }),
amazonReviewsURL =
'https://www.amazon.com/Meta-Quest-Pro-Oculus/product-reviews/B09Z7KGTVW/?reviewerType=all_reviews';
async function fetchReviews(url, reviews = []) {
try {
const response = await api.get(url, {
scraper: 'amazon-product-reviews',
});
if (response.statusCode === 200) {
const data = response.json.body;
console.log(data);
} else {
throw new Error(`API request failed with status: ${response.statusCode}`);
}
} catch (error) {
console.error(`API call failed: ${error.message}`);
}
}
// Call the fetchReviews function to start the scraping process
fetchReviews(amazonReviewsURL);