-
Notifications
You must be signed in to change notification settings - Fork 0
/
craigslist_jobsearch.py
54 lines (45 loc) · 2.02 KB
/
craigslist_jobsearch.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
#!/usr/bin/env python
from bs4 import BeautifulSoup
import requests
import pandas as pd
url = "https://minneapolis.craigslist.org/search/sof"
npo_jobs = {}
job_no = 0
while True:
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data, 'html.parser')
jobs = soup.find_all('p', {'class': 'result-info'})
print("\n[+] Start job search\n")
for job in jobs:
title = job.find('a', {'class': 'result-title'}).text
location_tag = job.find('span', {'class': 'result-hood'})
location = location_tag.text[2:-1] if location_tag else "N/A"
date = job.find('time', {'class': 'result-date'}).text
link = job.find('a', {'class': 'result-title'}).get('href')
job_response = requests.get(link)
job_data = job_response.text
job_soup = BeautifulSoup(job_data, 'html.parser')
job_description = job_soup.find('section', {'id': 'postingbody'}).text
job_attributes_tag = job_soup.find('p', {'class': 'attrgroup'})
job_attributes = job_attributes_tag.text if job_attributes_tag else "N/A"
job_no += 1
npo_jobs[job_no] = [title, location, date, link, job_attributes, job_description]
print("-------------------")
print(">>> JOB FOUND <<<")
print("-------------------")
print("Job Title:", title, '\nLocation:', location, '\nDate:', date, '\nLink:', link, '\n')
print(job_attributes, '\nJob Description:', job_description)
print("-------------------")
print(">> End Job Desc. <<")
print("-------------------")
url_tag = soup.find('a', {'title': 'next page'})
if url_tag.get('href'):
url = 'https://minneapolis.craigslist.org' + url_tag.get('href')
print(url)
else:
break
print("\n[-] End job search", " ", "Total Jobs found:", job_no)
npo_jobs_df = pd.DataFrame.from_dict(npo_jobs, orient='index')
npo_jobs_df.columns = ['Job Title', 'Location', 'Date', 'Link', 'Job Attributes', 'Job Description']
npo_jobs_df.to_csv('npo_jobs.csv')