-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
116 lines (94 loc) · 4.29 KB
/
app.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
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver import ChromeOptions
# https://www.youtube.com/watch?v=cnPlKLEGR7E
scope = [
"https://spreadsheets.google.com/feeds",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive",
]
creds = ServiceAccountCredentials.from_json_keyfile_name("./creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("jobSearchTwo").sheet1
sheet.clear()
# makes class
class IndeedBot:
# init
def __init__(self):
opts = ChromeOptions()
opts.add_experimental_option("detach", True)
self.bot = webdriver.Chrome("./chromedriver/chromedriver.exe")
# executes search, copies up to 50 urls to global variable links
def findJobs(self):
bot = self.bot
jobs = list()
global links
links = list()
# run once
# https://www.indeed.com/jobs?as_and=web+developer+remote&as_phr=&as_any=&as_not=&as_ttl=&as_cmp=&jt=all&st=&as_src=&salary=&radius=25&l=&fromage=1&limit=50&sort=&psf=advsrch&from=advancedsearch
# https://www.indeed.com/jobs?as_and=web+developer+title%3Aremote&jt=all&fromage=1&limit=50&psf=advsrch&from=advancedsearch
# https://www.indeed.com/jobs?q=web+developer+title%3Ajunior&limit=50&fromage=1&radius=25&start=0&l=Chicago%2C+IL
# https://www.indeed.com/jobs?as_and=web+developer+javascript&as_phr=&as_any=&as_not=&as_ttl=junior&as_cmp=&jt=all&st=&as_src=&salary=&radius=25&l=United+States&fromage=3&limit=50&sort=date&psf=advsrch&from=advancedsearch
bot.get(
"https://www.indeed.com/jobs?as_and=web+developer+javascript&as_phr=&as_any=&as_not=&as_ttl=junior&as_cmp=&jt=all&st=&as_src=&salary=&radius=25&l=United+States&fromage=3&limit=50&sort=date&psf=advsrch&from=advancedsearch"
)
time.sleep(10)
# finds all titles
jobs = bot.find_elements_by_class_name("jobtitle")
# saves href values from all titles
links = [elem.get_attribute("href") for elem in jobs]
# find the jobs that can be applied to directly from indeed
def sortByApplyType(self):
bot = self.bot
global links
global sheet
count = 0
# enumerates over links
for idx, link in enumerate(links):
# goes to link
bot.get(link)
time.sleep(5)
# adds link to first column of sheet
sheet.update_cell(idx + 1, 1, link)
# gets values from job ad
jobName = bot.find_element_by_class_name(
"jobsearch-JobInfoHeader-title"
).text
jobCompany = bot.find_element_by_css_selector(
".jobsearch-InlineCompanyRating > div:first-of-type"
).text
jobLocation = bot.find_element_by_css_selector(
".jobsearch-InlineCompanyRating > div:last-of-type"
).text
# saves values to clumns in sheets
sheet.update_cell(idx + 1, 3, jobName)
sheet.update_cell(idx + 1, 4, jobCompany)
sheet.update_cell(idx + 1, 5, jobLocation)
try: # try quick apply button
print("clicking apply button")
# clicks on button
bot.execute_script(
'document.querySelector(".jobsearch-IndeedApplyButton-contentWrapper").click();'
)
print("saved to list")
# updates sheet for job as instant-apply
sheet.update_cell(idx + 1, 2, "insta-apply")
time.sleep(1)
# open new blank tab
count += 1
bot.execute_script("window.open();")
# switch to the new window which is second in window_handles array
bot.switch_to_window(bot.window_handles[count])
except:
# if click event fails, adds no to instant-apply column in sheet
print("no button")
sheet.update_cell(idx + 1, 2, "no")
jon = IndeedBot()
# gets urls from search results
jon.findJobs()
# goes through each url and saves info to row in sheets
jon.sortByApplyType()