-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.py
More file actions
144 lines (85 loc) · 3.38 KB
/
Copy pathtest3.py
File metadata and controls
144 lines (85 loc) · 3.38 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
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
__Author__ = "Soumil Nitin Shah"
__Version__ = '1.1.1'
__Email__ = "soushah@my.bridgeport.edu"
try:
import requests
import bs4
from bs4 import BeautifulSoup
import pandas as pd
except Exception as e:
print("Some Modules are Missing {}".format(e))
class WebCrawler(object):
def __init__(self, title = '',location = ""):
self._url = "https://www.indeed.com/jobs"
self._headers = {'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"}
self._title = title
self._location = location
self.params = {
'q': 'Python',
'l': 'Bridgeport, CT'}
def get(self):
try:
r = requests.get(url=self._url,
headers=self._headers ,
params=self.params)
return r.text
except Exception as e:
print("Failed to make response to Indeed")
class DataStructure():
def __init__(self):
self.data = {
'title':[],
'location':[],
'summary':[],
'date':[],
'link':[]
}
class DataCleaning(object):
def __init__(self, title = '', location = ""):
self._title = title
self._location = location
self._webcrawler = WebCrawler(self._title, self._location)
self.data = self._webcrawler.get()
self.datastructure = DataStructure()
def getData(self):
soup = BeautifulSoup(self.data, 'html.parser')
for x in soup.findAll('div', class_="jobsearch-SerpJobCard unifiedRow row result"):
title = x.find(class_="title").text.strip()
self.datastructure.data["title"].append(title)
location = x.find(class_="location accessible-contrast-color-location").text.strip()
self.datastructure.data["location"].append(location)
summary = x.find(class_="summary")
self.datastructure.data["summary"].append(summary.text)
date = x.find(class_="date")
self.datastructure.data["date"].append(date)
link = x.find('a', href=True)
base_url = "https://www.indeed.com/"
Final = base_url + link["href"]
self.datastructure.data["link"].append(Final)
data = list(zip(
self.datastructure.data["title"], self.datastructure.data["location"],
self.datastructure.data["summary"],self.datastructure.data["date"],
self.datastructure.data["link"]
))
df = pd.DataFrame(data=data, columns=["title", "location", "summary", "date", "link" ])
return df
class IndeedJobSearch(object):
def __init__(self, title = '', location = ""):
self.title = title
self.location = location
self.datacleaning = DataCleaning(title=self.title, location=self.location)
def getJobs(self):
data = self.datacleaning.getData()
return data
def saveCsv(self):
data = self.datacleaning.getData()
data.to_csv("Jobs.csv")
def saveExcel(self):
data = self.datacleaning.getData()
data.to_excel("job.xls")
if __name__ == "__main__":
jobsearch = IndeedJobSearch(title='Python', location="Bridgeport , CT")
data = jobsearch.getJobs()
print(data)
# jobsearch.saveExcel()
#jobsearch.saveCsv()