-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
35 lines (31 loc) · 869 Bytes
/
index.ts
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
import { chromium } from 'playwright';
interface Product {
name?: string;
url: string;
hasStock?: boolean;
}
const products: Product[] = [
{
url: 'https://www.amazon.com/dp/B0C2XXMPLY/?coliid=I38OD59C8PRP8C&colid=2RMR8T6DALZ0&psc=0&ref_=list_c_wl_lv_ov_lig_dp_it_im'
},
{
url: 'https://www.amazon.com/Geometry-Programmers-Oleksandr-Kaleniuk/dp/1633439607'
}
];
void (async () => {
// Setup
const browser = await chromium.launch({
headless: false
// slowMo: 30
});
const page = await browser.newPage();
for (const product of products) {
await page.goto(product.url);
const getTitle = (await page.textContent('#title'))?.trim();
const hasStock = !((await page.$('#buy-now-button')) == null);
product.name = getTitle;
product.hasStock = hasStock;
console.log(product);
}
await browser.close();
})();