-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (42 loc) · 1.83 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
const puppeteer = require('puppeteer');
async function performSearch(number, keysData) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
'https://portaleservices.scfhs.org.sa/Pages/RegistrationValidity.aspx?lang=ar')
await page.waitForSelector('*');
// Perform actions
await page.select('#DDLSearchType', 'RegistrationNumber');
// Use the provided number to fill in the input field
await page.type('input[name="txt_RegisterNo"]', number);
const confirmText = await page.$eval('input[name="result"]', (input) => input.value);
await page.type('input[name="txt_RandomNumber"]', confirmText);
await page.click('input[name="btn_Search"]');
try{
await page.waitForSelector('th');
await page.waitForSelector('td');
// Create a dictionary with keys and values
const dataDict = await page.evaluate(() => {
const tableKeys = Array.from(document.querySelectorAll('th'));
const tableValues = Array.from(document.querySelectorAll('td'));
const dict = {};
const keysData = ['SCHSRegistrationNo', 'arName', 'enName', 'regStatus', 'regValidity', 'classification', 'type', 'sprecializtion', 'expirationDate'];
tableKeys.forEach((key, index) => {
dict[keysData[index]] = tableValues[index].textContent.trim();
});
return dict;
});
// Export the dictionary as JSON
const fs = require('fs');
fs.writeFileSync('output.json', JSON.stringify(dataDict, null, 2));
await browser.close();
}
catch(error){
console.log(error )
await browser.close();
}
// Wait for the table to load
}
// Example usage
const registrationNumber = '19089486';
performSearch(registrationNumber);