-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_scraper.py
54 lines (44 loc) · 1.73 KB
/
job_scraper.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
import requests
from bs4 import BeautifulSoup
def fetch_job_listings(keyword, location):
# Example URL (replace with actual job board URL)
url = f"https://www.examplejobboard.com/jobs?q={keyword}&l={location}"
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
jobs = []
for job_elem in soup.find_all('div', class_='job-listing'):
title_elem = job_elem.find('h2', class_='job-title')
company_elem = job_elem.find('div', class_='company')
location_elem = job_elem.find('div', class_='location')
description_elem = job_elem.find('div', class_='description')
if None in (title_elem, company_elem, location_elem, description_elem):
continue
job = {
'title': title_elem.text.strip(),
'company': company_elem.text.strip(),
'location': location_elem.text.strip(),
'description': description_elem.text.strip()
}
jobs.append(job)
return jobs
else:
print("Failed to fetch job listings")
return []
def display_jobs(jobs):
for job in jobs:
print(f"Title: {job['title']}")
print(f"Company: {job['company']}")
print(f"Location: {job['location']}")
print(f"Description: {job['description']}")
print("-" * 40)
def main():
keyword = input("Enter job keyword: ")
location = input("Enter job location: ")
jobs = fetch_job_listings(keyword, location)
if jobs:
display_jobs(jobs)
else:
print("No jobs found")
if __name__ == "__main__":
main()