-
Notifications
You must be signed in to change notification settings - Fork 1
/
execute-script.js
66 lines (51 loc) · 1.6 KB
/
execute-script.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
var Browser = require('./browser');
/*
* Let's scrap the landing.jobs
*
* - go to landing.jobs
* - click ('SEE OUR CURATED JOB OFFERS')
* - fetch $('#job-list li .job')
* -
* */
var browser = Browser('http://localhost:4444/wd/hub');
var offersPage = browser
.get('https://landing.jobs')
.waitForElement('link text', 'SEE OUR CURATED JOB OFFERS', 5000)
.element('link text', 'SEE OUR CURATED JOB OFFERS')
.click()
.then(fetchOffers)
.catch(console.log.bind(console, 'ERROR: '));
function fetchOffers(page) {
offersPage
.waitForElement('css selector', '#job-list', 5000)
.execute(extractFunctionBody(landingJobsScript))
.then(printOffers)
.catch(console.log.bind(console, 'ERROR: '));
}
function printOffers(offers) {
offers.forEach(function(offer) {
var result = {
'Company Name': offer.company_name,
'Job Title': offer.job_title,
'Short Description': offer.short_desc,
'Reward': offer.reward_value
};
console.log(result);
});
}
function extractFunctionBody(fn) {
return fn.toString().match(/function\s+.+\(.*\)\s+\{([\s\S]+)\}/)[1];
}
function landingJobsScript() {
var $offers = $('#job-list li .job');
return $offers.map(mapper);
function mapper(idx, offer) {
var result = {};
var $offerDetails = $(offer).find('.description');
result.company_name = $offerDetails.find('.company_name').text().trim();
result.job_title = $offerDetails.find('.job_title').text().trim();
result.short_desc = $offerDetails.find('.short_desc').text().trim();
result.reward_value = $(offer).find('.reward_value p').last().text();
return result;
}
}