-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloFsi.js
31 lines (23 loc) · 910 Bytes
/
helloFsi.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
const { chromium } = require("playwright");
const gotoUrl = "https://www.financialresearch.gov/financial-stress-index/";
async function scrapeData() {
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto(gotoUrl, { waitUntil: "load" });
const selectorIndex = ".latest-daily-observation .header span";
const selectorDate = ".latest-daily-observation .stat";
await page.waitForSelector(selectorIndex);
await page.waitForSelector(selectorDate);
const currentIndex = await page.textContent(selectorIndex);
const dateInfo = await page.textContent(selectorDate);
await browser.close();
return { currentIndex: currentIndex.trim(), dateInfo };
}
(async () => {
try {
const data = await scrapeData();
console.log("Scraped data:", data);
} catch (error) {
console.error("Error during scraping:", error);
}
})();