-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjob_scraper.py
More file actions
97 lines (79 loc) · 3.1 KB
/
Copy pathjob_scraper.py
File metadata and controls
97 lines (79 loc) · 3.1 KB
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
import requests
from bs4 import BeautifulSoup
language = input("Language to search jobs for or leave blank and press ENTER: ")
location = input("City OR state to search for jobs or leave blank and press ENTER: ").replace(' ', '-')
if language:
#Language and location
if location:
URL = f'https://www.monster.com/jobs/search/?q={language}&where={location}&stpage=1&page=3'
#Only language
else:
URL = f'https://www.monster.com/jobs/search/?q={language}&stpage=1&page=3'
#if only location
elif location:
URL = f'https://www.monster.com/jobs/search/?where={location}&stpage=1&page=3'
#if nothing
else:
URL = f'https://www.monster.com/jobs/search/?q=Software-Developer'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find(id='ResultsContainer')
job_elems = results.find_all('section', class_='card-content')
print("\n", end='')
print("*" * 75, "\n")
input("Search results loaded. \nPress ENTER to print results:")
#Return results of job search
print("Printing jobs:")
# this will print every job posting as text
for job_elem in job_elems:
title_elem = job_elem.find('h2', class_='title', string=lambda text: f'{language}' in text.lower())
company_elem = job_elem.find('div', class_='company')
location_elem = job_elem.find('div', class_='location')
link = job_elem.find('a')
#monster has a Section html element that DOESN"T have info, so without this,
#it'll return an error with the print statements afterwards
if None in (title_elem, company_elem, location_elem, link):
continue
print(title_elem.text.strip())
print(company_elem.text.strip())
print(f"{location_elem.text.strip()}")
print(f"Apply here: {link['href']}\n")
print("-" * 75,'\n' )
#-----------------------*********-----------------------
####This feature will be added in the future after I get the bugs out
# Filter by role
# role = input("Role to filter results by or leave blank (e.g. data scientist or junior):")
# print(role)
# if role:
# jobs_by_role = results.find_all('h2',
# string=lambda text: f'{role}' in text.lower())
#
# for roles in job_elems:
# title_elem = jobs_by_role.find('h2', class_='title')
# company_elem = jobs_by_role.find('div', class_='company')
# location_elem = jobjobs_by_role_elem.find('div', class_='location')
#
# if None in (title_elem, company_elem, location_elem):
# continue
#
# for jobs in jobs_by_role:
# print(title_elem.text.strip())
# print(company_elem.text.strip())
# print(f"{location_elem.text.strip()}", "\n")
#
#
# for job in jobs_by_role:
# title_elem = job_elem.find('h2', class_='title')
# company_elem = job_elem.find('div', class_='company')
# location_elem = job_elem.find('div', class_='location')
#
# if None in (title_elem, company_elem, location_elem):
# continue
#
# print(title_elem.text.strip())
# print(company_elem.text.strip())
# print(f"{location_elem.text.strip()}", "\n")
# print("-" * 75,'\n')
#
#
# print(f"Available Entry-level Jobs: {len(entry_jobs)}")