-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrapeWebsite.js
More file actions
74 lines (60 loc) · 1.63 KB
/
scrapeWebsite.js
File metadata and controls
74 lines (60 loc) · 1.63 KB
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
const { chromium } = require("playwright");
async function scrapeWebsite(url) {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
ignoreHTTPSErrors: true, // ✅ FIX SSL errors
});
const page = await context.newPage();
try {
await page.goto(url, {
timeout: 20000,
waitUntil: "networkidle", // ✅ WAIT PROPERLY
});
// small delay for dynamic content
await page.waitForTimeout(1500);
const html = (await page.content()).toLowerCase();
const hasPhone =
/\d{3}[-.\s]?\d{3}[-.\s]?\d{4}/.test(html) ||
html.includes("tel:") ||
html.includes("call") ||
html.includes("phone");
const hasForm =
html.includes("<form") ||
html.includes("contact") ||
html.includes("get a quote") ||
html.includes("request service") ||
html.includes("submit");
const hasChat =
html.includes("intercom") ||
html.includes("drift") ||
html.includes("tawk") ||
html.includes("chat");
const hasBooking =
html.includes("book") ||
html.includes("schedule") ||
html.includes("appointment") ||
html.includes("reserve");
await browser.close();
return {
websiteUrl: url,
scraped: true,
error: null,
hasForm,
hasChat,
hasBooking,
hasPhone,
};
} catch (e) {
await browser.close();
return {
websiteUrl: url,
scraped: false,
error: e.message || "scrape_failed",
hasForm: false,
hasChat: false,
hasBooking: false,
hasPhone: false,
};
}
}
module.exports = { scrapeWebsite };