-
Notifications
You must be signed in to change notification settings - Fork 2
/
scraper.js
146 lines (123 loc) · 4.28 KB
/
scraper.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const request = require('request');
const cheerio = require('cheerio');
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("tracker").addEventListener("click", tracker);
});
function tracker(){
let urlname = "";
let domain = "";
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
var tab = tabs[0];
var url = new URL(tab.url);
var site = url.hostname.split('.')[1];
alert(url);
alert(site);
urlname = url;
domain = site;
let options = {
url : urlname,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}
};
if (domain.toLowerCase() === "indeed") {
request ('https://in.indeed.com/viewjob?jk=8bc7de9b52a7fdbb&tk=1f56fke9nst68800&from=serp&vjs=3&advn=8531100203438512&adid=361848589&ad=-6NYlbfkN0A0sLjryQUNkc81K2goHfqpo9JHml6Vo2yWT4XuRGLXtt0Plp8naQ2M7aL2M5qwnGbk6X_onERNWufoFvpkMECfXh8Q5AYrCHdvuytdePQygAsodW8PVUvM9KNbLzpIW7Z7CBrynVPT89PT_eWcCPta0swFxvfCRhRuljeX6IViblor47sefnl-chWn6UypP1FQT42Fa-8QGV-tT3MTZ7lkE6kFSKm94S4XD1NOojSnbmOXOXvrg1VdfGPhbvvu0sCiilmRQED3y-Gxk8rmyTfjeLevkwTeswzlOppHjwDF6AV-AnZurnErGarVpJ7pzxM=&sjdu=4-j9Ft8zRiwjAAIoOpx63C9tSnla7vOMPwzolHr1KN_42LO-dgdIci_pnNfxQFzG0qnU6aiesBK8ObomtJnjrLnourDm_m3C3PvTfNIWoqAe9xnSsP4O3GI4KNjZRNvCvrMAbcovb_12btMW_Ds9ErYZbYbIMA0VtO9IBFBI1jdEcZZct-fgQcdcdZqESJcm0suMjyO8GYKvk4rvrDXJ9X-YrR6Klu8nSJTjrK0B8zDmh6YAq6w0AOiDt48xkjvLw9wzjkTtskG6RrqnvDhxeSxLTOoFlnNbXr749G5bbSI', (error, resp, html)=> {
if (!error && resp.statusCode == 200){
const $ = cheerio.load(html);
const title = $('.jobsearch-JobInfoHeader-title');
// alert(title.html());
let other = [];
$('.jobsearch-JobInfoHeader-subtitle div').each((i, el) => {
other.push($(el).text());
});
const company = other[1];
const location = other[other.length - 1];
// alert(company);
// alert(location);
show_preview();
document.getElementById("job-title").value = title.html();
document.getElementById("company-name").value = company;
document.getElementById("job-location").value = location;
document.getElementById("saveApplication").addEventListener("click", () => {
if(!localStorage.getItem("janus-email")){
alert("Please add your email");
show_settings();
} else {
saveToDatabase({
title: title.html(),
company: company,
location: location,
link: url,
status: 'Applied',
email: localStorage.getItem("janus-email"),
});
}
});
}
else {
console.log(error, resp.statusCode);
}
});
}
else if (domain.toLowerCase() === "glassdoor") {
request (options , (error, resp, html)=> {
if (!error && resp.statusCode == 200){
const $ = cheerio.load(html);
const title = $('.e11nt52q6');
const jobTitle = title.text();
// alert("title "+jobTitle);
const location = $('div .e11nt52q2');
const jobLocation = location.html();
// alert("location "+jobLocation);
const company = $('div .e11nt52q1');
const companyName = company.text().replace(/[^a-zA-Z]/g, '');
// alert("company "+companyName);
show_preview();
document.getElementById("job-title").value = jobTitle;
document.getElementById("company-name").value = companyName;
document.getElementById("job-location").value = jobLocation;
document.getElementById("saveApplication").addEventListener("click", () => {
if(!localStorage.getItem("janus-email")){
alert("Please add your email");
show_settings();
} else {
saveToDatabase({
title: jobTitle,
company: companyName,
location: jobLocation,
link: url,
status: 'Applied',
email: localStorage.getItem("janus-email"),
});
}
});
}
else {
console.error(error, resp.statusCode);
}
});
}
else {
alert("nothing works")
}
});
}
function saveToDatabase(data) {
fetch("https://janus-dot-hackathon-313211.uc.r.appspot.com/applications/", {
method: "POST",
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function(res){
// alert(res.status);
if(res.status === 200) {
hide_preview();
}
})
// .then(function(resultdata){ alert( JSON.stringify( resultdata ) ) })
.catch(function(err){
alert("error "+err)
});
}