-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (73 loc) · 2.93 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const puppeteer = require('puppeteer');
const express = require('express');
const cron = require('node-cron');
const axios = require('axios')
const app = express();
app.use(express.json());
const port = 7051;
app.post('/daily-update-naukri-profile', async (req, res) => {
try {
let loginModel = {
url: 'https://www.naukri.com/nlogin/#',
username: 'input[id="usernameField"]',
password: 'input[id="passwordField"]',
logoutUrl: 'https://www.naukri.com/nlogin/logout'
};
let editModel = {
url: 'https://www.naukri.com/mnjuser/profile?id=&altresid',
attachCV: 'input[id="attachCV"]'
};
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(loginModel.url);
await page.waitFor(loginModel.username);
await page.waitFor(loginModel.password);
await page.type(loginModel.username, req.body.username);
await page.type(loginModel.password, req.body.password);
await page.keyboard.press('Enter');
await page.waitForNavigation();
await page.evaluate(() => {
if (document.querySelector('.feedbackBtn')) {
document.querySelector('.feedbackBtn').click();
} else {
return;
}
});
let timestamp = new Date();
let fileName;
fileName = './screenshots/' + timestamp.toDateString() + ' login ' + '.png';
await page.screenshot({ path: fileName, fullPage: true });
await page.goto(editModel.url);
await page.evaluate(() => {
let editElement = document.querySelectorAll('div.widgetHead')[1];
editElement.querySelectorAll('span')[1].click();
});
fileName = './screenshots/' + timestamp.toDateString() + ' update ' + '.png';
await page.screenshot({ path: fileName, fullPage: true });
await page.evaluate(() => {
document.querySelector('#saveKeySkills').click();
});
await page.goto(editModel.url);
await page.waitFor(editModel.attachCV);
fileName = './screenshots/' + timestamp.toDateString() + ' updated ' + '.png';
await page.screenshot({ path: fileName, fullPage: true });
await page.goto(loginModel.logoutUrl);
await browser.close();
res.send('success!!!')
} catch (err) {
}
});
cron.schedule('0 1 * * *', () => {
axios.post('http://localhost:7051/daily-update-naukri-profile', {
"username": "edit your email id",
"password": "add your password"
})
.then((res) => {
console.log(`statusCode: ${res.status}`)
console.log(res.data)
})
console.log('running a task every day 6 am');
});
app.listen(port, () =>
console.log(`Naukri update app listening on port ${port}`),
);