-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
537 lines (285 loc) · 10.6 KB
/
main.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
from flask import Flask, render_template, redirect , url_for
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
import requests
from bs4 import BeautifulSoup
"""
author: Mayukh Pankaj
date: 10/5/2021
Woogle - a Job scraping web application.
LEAD 2.0
"""
#initialising global variables
global gdata , lidata , isdata, indata , tdata , usr_input , loc
gdata = []
lidata = []
isdata = []
indata = []
tdata = []
app = Flask(__name__)
app.config['SECRET_KEY'] = 'xyz' #CSRF token
class searchform(FlaskForm):
text = StringField('Search',validators=[DataRequired()])
location = StringField('location')
submit = SubmitField('SEARCH')
# function for gsearch
def gsearch(text,loc=""):
text=text.replace(' ', '+')
headers = {
'User-agent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
}
if not loc:
searchurl='https://google.com/search?q='+text+'+jobs'
else:
searchurl='https://google.com/search?q='+text+'+jobs+in+'+loc
print(searchurl)
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
results = soup.find_all(class_='yuRUbf')
r_no = min(3,len(results))
ctr = 0
dataframe =[]
for result in results:
if(ctr>=r_no):
break
try:
title = result.find(class_='LC20lb DKV0Md').string
link = result.find('a')['href']
desc = result.next_sibling.text.strip()
data_item = {
'title':title,
'desc':desc,
'link':link
}
except:
break
dataframe.append(data_item)
ctr+=1
return dataframe
# linkedin search
def linkedin(text,loc=""):
text=text.replace(' ', '%20')
headers = {
'User-agent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
}
if not loc:
searchurl='https://www.linkedin.com/jobs/search?keywords='+text+'&location=India&geoId=&trk=public_jobs_jobs-search-bar_search-submit&position=1&pageNum=0'
else:
searchurl='https://www.linkedin.com/jobs/search?keywords='+text+'&location='+loc+'&geoId=&trk=public_jobs_jobs-search-bar_search-submit&position=1&pageNum=0'
print(searchurl)
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
cards = soup.find_all('a',class_='base-card__full-link')
print(len(cards))
l = len(cards)
#linkedin returns different class name sometimes requesting again gives required html.
while(not(l)):
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
cards = soup.find_all('a',class_='base-card__full-link')
l = len(cards)
ctr = 0
dataframe =[]
for card in cards:
if ctr >=4:
break
try:
link = card['href']
card = card.next_sibling.next_sibling
img = card.img['data-delayed-url']
card = card.next_sibling.next_sibling
title = card.h3.text.strip()
company = card.h4.text.strip()
location = card.find(class_='base-search-card__metadata').span.text.strip()
data_item = {
'title': title,
'company': company,
'location': location,
'img':img,
'link':link
}
except:
break
dataframe.append(data_item)
# print(title)
# print(company)
# print(location)
# print(img)
# print(link)
ctr+=1
return dataframe
# internshala search
def internshala(text,loc=''):
text=text.replace(' ', '%20')
headers = {
'User-agent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
}
if not loc:
searchurl='https://internshala.com/internships/keywords-'+text
else:
searchurl='https://internshala.com/internships/keywords-'+text+'-in-'+loc
print(searchurl)
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
cards = soup.find_all(class_='internship_meta')
cl = len(cards)
print(cl)
ctr=0
dataframe = []
for card in cards:
if ctr >=4:
break
try:
try:
title = card.find(class_='heading_4_5 profile').text.strip()
except:
title = ''
link = card.a['href']
link = 'https://internshala.com'+link
company = card.find(class_='heading_6 company_name').text.strip()
location = card.find(class_='location_link').text.strip()
el = card.find(class_='internship_other_details_container')
duration = el.contents[1].find(class_='ic-16-calendar').text.strip()
stipend = el.find(class_='stipend').text.strip()
end_date = el.find(class_='apply_by')
apply_by = end_date.contents[3].text.strip()
try:
img = card.find(class_='internship_logo').img['src']
img = 'https://internshala.com'+img
except:
img=''
# print(title,company,location,duration,stipend,apply_by,img,link)
card_data = {
'title':title,
'company':company,
'location':location,
'duration':duration,
'stipend':stipend,
'apply_by':apply_by,
'img':img,
'link':link
}
except:
break
dataframe.append(card_data)
ctr+=1
return dataframe
# indeed search
def indeed(text,loc):
text=text.replace(' ', '+')
headers = {
'User-agent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
}
if not loc:
searchurl='https://in.indeed.com/jobs?q='+text
else:
searchurl='https://in.indeed.com/jobs?q='+text+'&l='+loc
print(searchurl)
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
cards = soup.find_all(class_='title')
data = []
ctr = 0
for card in cards:
if ctr >=4:
break
try:
title = card.a.text.strip()
link = card.a['href'].replace('/rc/clk?','')
# print(len(link))
if(len(link)>60):
link='https://in.indeed.com'+link #indeed's job page & advertised job page have different url
else:
link='https://in.indeed.com/viewjob?'+link
card = card.parent
company = card.find(class_='company').text.strip()
location = card.find(class_='location accessible-contrast-color-location').text.strip()
description = card.find(class_='summary').text
# print(title,company,location,link,description)
data_item = {
'title':title,
'company':company,
'location':location,
'description': description,
'link':link
}
except:
break
data.append(data_item)
ctr+=1
return data
# times job search
def timesjob(text,loc):
text=text.replace(' ', '%20')
headers = {
'User-agent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
}
if not loc:
searchurl='https://www.timesjobs.com/candidate/job-search.html?searchType=personalizedSearch&from=submit&txtKeywords='+text
else:
searchurl='https://www.timesjobs.com/candidate/job-search.html?searchType=personalizedSearch&from=submit&txtKeywords='+text+'+&txtLocation='+loc
print(searchurl)
response = requests.get(searchurl,headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
jobs = soup.find_all('li',class_='clearfix job-bx wht-shd-bx')
ctr = 0
data = []
for job in jobs:
if ctr >=4:
break
try:
title = job.find('h2').text.strip()
company= job.find('h3',class_='joblist-comp-name').text.strip()
skills = job.find('span',class_='srp-skills').text.strip()
datalabel = job.find('ul',class_='top-jd-dtl clearfix')
# using navigation for years & location without any class or id
years = datalabel.next_element.next_element.next_element.next_sibling
location = datalabel.contents[3].span.text
link = job.header.h2.a['href']
data_item = {
'title': title,
'company': company,
'duration': years,
'location': location,
'skills': skills,
'link' : link
}
except:
break
data.append(data_item)
ctr +=1
return data
@app.route('/', methods=['POST','GET'])
def home():
form = searchform()
gl=0
if form.validate_on_submit():
print('submit clicked')
global usr_input , loc
user_input = form.text.data
usr_input = form.text.data
loc = form.location.data
print(loc)
print(user_input)
global gdata , lidata , isdata , indata , tdata
gdata = gsearch(user_input,loc) #gsearch
lidata = linkedin(user_input,loc) #linkedin
isdata = internshala(user_input) #internshala
indata = indeed(user_input,loc) #indeed
tdata = timesjob(user_input,loc) #times job
return redirect(url_for('result')) #redirecting to results page
return render_template('index.html',form=form)
@app.route('/result',methods=['POST','GET'])
def result():
return render_template('result.html',gdata=gdata, ldata =lidata , isdata=isdata, indata=indata, tdata=tdata,usri = usr_input,loc=loc)
@app.route('/about')
def about():
return render_template('about.html')
if __name__=='__main__':
app.run()