/
krs.py
354 lines (230 loc) · 12.6 KB
/
krs.py
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import numpy as np
import pandas as pd
import requests, re
import datetime
import time
from selenium import webdriver
from bs4 import BeautifulSoup as BS
from urllib.request import urljoin
from pytablewriter import MarkdownTableWriter
#from run import executable_path
chrome_path = r'C:\Users\krajasekhara\PycharmProjects\CLL jobs scraping\drivers\chromedriver_win32\chromedriver.exe'
fields_needed=['Company Name',
'Job Title',
'Job Description',
'Job Location',
'Job Type',
'Years of Experience',
'Job Department',
'Job Specific URL',
'Career Page URL',
'Market/Sector']
def niramai(company_name,companies_details):
# company_name = 'NIRAMAI'
# career_page_url = 'https://www.niramai.com/careers/'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
html = requests.get(career_page_url).text
soup = BS(html, 'lxml')
divs = soup.find('div', {'class': 'sjb-listing'})
divs_all = divs.find_all('div', {'class': 'list-data'})
df = pd.DataFrame(columns=fields_needed)
for div in divs_all:
job_title = div.find('span', {"class": "job-title"}).get_text().strip()
job_description = div.find('div', {"class": "job-description"}).find_all('p')[0].get_text().strip()
job_location = div.find('div', {'class': 'job-location'}).get_text().strip()
job_type = div.find('div', {'class': 'job-type'}).get_text().strip()
years_of_experience = np.nan
job_department = np.nan
job_specific_url = div.find('div', {"class": "job-description"}).find_all('p')[1].find('a')['href']
# job_specific_url = urljoin(career_page_url,div.find('h4').find('a')['href'])
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
return df
def locus(company_name,companies_details):
# company_name = 'Locus'
# career_page_url = 'https://locus.freshteam.com/jobs'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
html = requests.get(career_page_url).text
soup = BS(html, 'lxml')
divs_all = soup.find('div', {'class': 'job-role-list'}).find_all('li')
df = pd.DataFrame(columns=fields_needed)
for div in divs_all:
job_title = div.find('a', {"class": "job-title"}).get_text().strip()
job_description = np.nan
# job_description = div.find('a', {"class": "job-desc text"}).get_text().strip() #company intro available
job_location = re.sub('[\s]+', ' ',div.find('div', {'class': 'job-location'}).find('a').get_text().strip().replace("\n"," ")).split(" ")[0]
job_type = " ".join(re.sub('[\s]+', ' ',div.find('div', {'class': 'job-location'}).find('a').get_text().strip().replace("\n"," ")).split(" ")[1:])
years_of_experience = np.nan
if div.find('h5') is None:
try:
job_department = job_department
except Exception as e:
job_department = np.nan
else:
job_department = re.sub('[\s]+', ' ', div.find('h5').get_text().strip()).split(" ")[0]
job_specific_url = urljoin(career_page_url, div.find('a', {"class": "job-title"})['href'])
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
return df
def oneorigin(company_name,companies_details):
# company_name = 'ONEORIGIN'
# career_page_url = 'https://www.oneorigin.us/careers/'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
headers = {'User-Agent': 'Mozilla/5.0'}
html = requests.get(career_page_url, headers=headers).text
soup = BS(html, 'lxml')
divs = soup.find('div', {'class': 'column medium-12 col-md-12'})
divs_all = divs.find_all('div', {'class': 'job-preview clearfix'})
df = pd.DataFrame(columns=fields_needed)
for div in divs_all:
job_title = div.find('div', {"class": "job-content"}).find('h5').find('span').get_text().strip()
job_description = div.find('div', {"class": "job_custom_message"}).get_text().strip()
job_location = np.nan
job_type = div.find('div', {"class": "job-additional-information"}).find('span').get_text().strip()
years_of_experience = np.nan
job_department = np.nan
job_specific_url = urljoin(career_page_url,
div.find('div', {"class": "job-content"}).find('h5').find('a')['href'])
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
return df
def alphasense(company_name,companies_details):
# company_name = 'ALPHASENSE'
# career_page_url = 'https://www.alpha-sense.com/careers'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get(career_page_url)
driver.minimize_window()
# driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;") #;var lenOfPage=document.body.scrollHeight;return lenOfPage;
time.sleep(15)
df = pd.DataFrame(columns=fields_needed)
try:
departments = driver.find_elements_by_class_name('department')
for department in departments:
job_department = department.find_element_by_tag_name('h4').text.title()
jobs = department.find_elements_by_class_name('job')
for job in jobs:
job_title = job.find_element_by_class_name('description').text.split('\n')[0]
job_description = np.nan
job_location = job.find_element_by_class_name('location').text
job_type = np.nan
years_of_experience = np.nan
job_specific_url = job.find_element_by_class_name('cta').find_element_by_tag_name('a').get_attribute('href')
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
except Exception as e:
print(e)
print("<<<<<<<<<<<<<<<<<<<<< This company got an issue %s >>>>>>>>>>>>>>>>>>>>>>>" % career_page_url)
finally:
driver.quit()
return df
def sayint(company_name,companies_details):
# company_name = 'sayint'
# career_page_url = 'https://sayint.freshteam.com/jobs'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
html = requests.get(career_page_url).text
soup = BS(html, 'lxml')
divs = soup.find('div', {'class': 'job-role-list'})
divs_roles = divs.find_all('ul', {'class': 'open-list'})
df = pd.DataFrame(columns=fields_needed)
for div_role in divs_roles:
job_department = re.sub('[\s]+', ' ',div_role.find('div', {"class": "role-title"}).h5.get_text().strip().replace("\n"," ")).split(" ")[0]
divs_all = div_role.find_all('li', {'class': 'heading'})
for div in divs_all:
job_title = div.find('a', {"class": "job-title"}).get_text().strip()
job_description = div.find('a', {"class": "job-desc text"}).get_text().strip()
job_location = re.sub('[\s]+', ' ',div.find('div', {'class': 'job-location'}).find('a').get_text().strip().replace("\n"," ")).split(" ")[0]
job_type = " ".join(re.sub('[\s]+', ' ',div.find('div', {'class': 'job-location'}).find('a').get_text().strip().replace("\n", " ")).split(" ")[1:])
years_of_experience = np.nan
job_specific_url = urljoin(career_page_url, div.find('div').find('a', {"class": "job-desc text"})['href'])
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
return df
def casetext(company_name,companies_details):
# company_name = 'CASETEXT'
# career_page_url = 'https://jobs.lever.co/casetext/'
print(company_name)
career_page_url = companies_details[company_name]['career_page_url']
sector = companies_details[company_name]['sector']
html = requests.get(career_page_url).text
soup = BS(html, 'lxml')
div_posting = soup.find('div', {'class': 'postings-group'})
divs_posting = div_posting.find_all('div', {'class': 'posting'})
df = pd.DataFrame(columns=fields_needed)
for div in divs_posting:
job_title = div.find('a', {"class": "posting-title"}).find('h5').get_text().strip()
job_description = np.nan
job_location = div.find('span',
{"class": "sort-by-location posting-category small-category-label"}).get_text().strip()
job_type = np.nan
years_of_experience = np.nan
job_department = div.find('span',
{"class": "sort-by-team posting-category small-category-label"}).get_text().strip()
job_specific_url = urljoin(career_page_url, div.find('a', {"class": "posting-title"})['href'])
df = df.append(pd.Series(data=[company_name,
job_title,
job_description,
job_location,
job_type,
years_of_experience,
job_department,
job_specific_url,
career_page_url,
sector], index=fields_needed), ignore_index=True)
return df
#niramai('Niramai','https://www.niramai.com/careers/')
#locus('Locus','https://locus.freshteam.com/jobs')
#oneorigin('OneOrigin', 'https://www.oneorigin.us/careers/')
#alphasense('alphaSense', 'https://www.alpha-sense.com/careers')
#sayint('sayint','https://sayint.freshteam.com/jobs')
#casetext('CASETEXT','https://jobs.lever.co/casetext/')