-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit jobs test.py
241 lines (156 loc) · 5.24 KB
/
git jobs test.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import requests
import json
from bs4 import BeautifulSoup
from urllib.request import urlopen
# In[18]:
source = requests.get('https://jobs.github.com/positions').text
soup = BeautifulSoup(source, 'lxml')
summary = ""
#--> prints out all job titles, locations, company, and fulltime or not full time
# In[3]:
#summary = soup.find('div', class_='column main').text (does same thing)
#the "table" and "positionlist" strings were found using inspect element on the website (f12)
def positionList():
try:
summary = soup.find('table', class_='positionlist').text
except:
summary = soup.find('table', class_='positionlist')
# In[4]:
#prints the location of each job
#print(soup.find_all('span', class_='location'))
def getLocations():
locations = []
for loc in soup.find_all('span', class_='location'):
locations.append(loc.text)
print(locations)
# In[5]:
#prints the time the job was posted
#print(soup.find_all('span', class_='relatized'))
def getTimes():
timePosted = []
for time in soup.find_all('span', class_='relatized'):
timePosted.append(time.text)
print(timePosted)
# In[6]:
#prints the company name
#print(soup.find_all('a', class_='company'))
def getCompany():
allCompany = []
for co in soup.find_all('a', class_='company'):
allCompany.append(co.text)
print(allCompany)
# In[7]:
#prints all the job titles
#title container doesn't have class so it searches nearest parent container's class
def getTitles():
for table in soup.find_all('td', {'class':'title'} ):
links.append(table.find_all('h4'))
#print(links)
jobTitles = []
for title in links:
try:
jobTitles.append(title.text)
except: #titles are returned strangely, some results are returned as lists
jobTitles.append(title[0].text)
print(jobTitles)
# In[8]:
#prints full time or contract work
#class names vary
def getWork():
print(soup.find_all('strong', class_='fulltime'))
print(soup.find_all('strong', class_='contract'))
# In[31]:
# returns a list which contains sublists for each job entry
jobs = []
links = []
def getJobsFormatted():
for job in soup.find_all('tr', {'class':'job'} ):
tmp = job.text.strip().split('\n')
jb = []
for x in tmp:
y = x.strip()
if len(y) > 1 and not "\t" in y:
jb.append(x.strip())
jobs.append(jb)
print(jobs)
# In[4]:
# helper function for getJobWLnks
# assumes url is a job page on the github jobs api
# returns the link where the user can apply to the company
# or this page (as specified by url) if none provided
def getLink(url):
newSrc = requests.get(url).text
newSoup = BeautifulSoup(newSrc, 'lxml')
jobLink = newSoup.find('div', {'class':'highlighted'}).find('a')
return url if jobLink == None else jobLink['href']
# In[19]:
jobsWL = []
# similar to getJobsFormatted
# however it also includes a link where the user can apply to the company
def getJobWLnks():
for job in soup.find_all('tr', {'class':'job'} ):
link = getLink(job.find('td', {'class':'title'}).find('h4').find('a')['href'])
tmp = job.text.strip().split('\n')
jb = []
for x in tmp:
y = x.strip()
if len(y) > 1 and not "\t" in y:
jb.append(x.strip())
jb.append(link)
jobsWL.append(jb)
#getJobWLnks()
#print(jobsWL)
# In[21]:
#getJobWLnks()
#print(jobsWL)
# In[14]:
multPageJobsWL = []
# includes links and searches multiple pages
def getJobLP(numPages):
for i in range (1, numPages):
url = 'https://jobs.github.com/positions'
finalurl = url + 'page=' + str(i)
source = requests.get(url).text
soup = BeautifulSoup(source, 'lxml')
for job in soup.find_all('tr', {'class':'job'} ):
link = getLink(job.find('td', {'class':'title'}).find('h4').find('a')['href'])
tmp = job.text.strip().split('\n')
jb = []
for x in tmp:
y = x.strip()
if len(y) > 1 and not "\t" in y:
jb.append(x.strip())
jb.append(link)
multPageJobsWL.append(jb)
# In[16]:
#getJobLP(2)
#print(multPageJobsWL)
# In[2]:
multPageLocJobsWL = []
# searches multiple pages and the given location
# also returns links
def getJobLLP(loc, numPages):
for i in range (1, numPages):
loc = loc.replace(' ', '+')
url = 'https://jobs.github.com/positions' + '?page=' + str(i)
#resolvedURL = url + "?page=" + str(i)
finalURL = url + '&location='+ loc
source = requests.get(finalURL).text
soup = BeautifulSoup(source, 'lxml')
for job in soup.find_all('tr', {'class':'job'} ):
link = getLink(job.find('td', {'class':'title'}).find('h4').find('a')['href'])
tmp = job.text.strip().split('\n')
jb = []
for x in tmp:
y = x.strip()
if len(y) > 1 and not "\t" in y:
jb.append(x.strip())
jb.append(link)
multPageLocJobsWL.append(jb)
# In[5]:
#getJobLLP('chicago', 3)
#print(multPageLocJobsWL)
# In[ ]: