-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobScrape.py
More file actions
64 lines (49 loc) · 2.09 KB
/
jobScrape.py
File metadata and controls
64 lines (49 loc) · 2.09 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
# importing modules
import requests
from bs4 import BeautifulSoup
import pandas as pd
# function to access a page given a number and extracting the data
def extract(page):
headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"}
url = f"https://www.simplyhired.com/search?q=python&l=Houston%2C+TX&pn={page}&job=hWU1DVDIFACfIAUVaFlp4DHFSFe4He6H8G9YSk-33J7voXUdccCbMQ"
r = requests.get(url, headers)
soup = BeautifulSoup(r.content, 'html.parser')
return soup
# function to access the job listing's title, company, and other important details
def transform(soup):
# Finds jobs in page
divs = soup.find_all('div', class_ = 'SerpJob-jobCard')
# iterates through every job and extracts data
for job in divs:
title = job.find('a').text.strip()
company = job.find('span', class_ = 'JobPosting-labelWithIcon jobposting-company').text.strip()
# Used try/except statements here due to not being able to extract certain text data
try:
salary = job.find('div', class_ = 'jobposting-salary SerpJob-salary').text
except:
salary = job.find('div', class_ = 'SerpJob-metaInfoLeft').text
try:
rating = job.find('span', class_ = 'CompanyRatings-serp').text
except:
rating = "No rating given."
summary = job.find('p', class_ = 'jobposting-snippet').text
# dictionary containing all data
job = {
'title': title,
'company': company,
'rating': rating,
'summary': summary,
'salary': salary
}
# dictionary data being stored in a list
joblist.append(job)
return
joblist = []
for i in range(0, 3):
c = extract(1)
transform(c)
# stores data from list into a dataframe using pandas
df = pd.DataFrame(joblist)
print(df.head())
# creates a csv (Comma-separated values) file and stores the dataframe in that file
df.to_csv('jobs.csv')