Category: Bots

I have had quite a lot of free time this so I decided to make some bots with python and selenium. This bot applies to jobs on craigslist automatically based on what you search. It goes to each posting in a specific query and sends cover letter complete with resume attachment.

Let’s get started.

First you will need to download and a install python 3.5 if you don’t already have it you can download it here.

Now we have python installed on our computers let’s install our dependencies for this bot we will need to install selenium. Python installations should come with pip so you can install selenium by typing “pip install selenium”.

pip install selenium
We can start writing our script now. Lets begin by importing all the dependencies we will use.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import urllib.parse as urlparse
import time
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib

Now that we have our browser open and on the page we want next we have to fill out the search form so we can get the jobs we want. Selenium let’s us easily target elements on a page, fill out forms, and it’ll even let you simulate keystrokes and clicks.

def getJobs(q, un , pw, cover, res): browser = webdriver.Chrome('chromedriver.exe')#this opens the browser browser.get("http://buffalo.craigslist.org/search/jjj")#tells the browser which page to go to elem = browser.find_element_by_name("query")#we get the element by name elem.clear() elem.send_keys(q)#fills out form with our query elem.send_keys(Keys.RETURN)#simulates pressing the enter key

This should have us on the page we want with the jobs we were looking for. Now we need to make a list of all the urls for each job listing.

for link in links: #We take the job title and url and add it to a list so we have a list of lists jobLinks.append([link.text,link.get_attribute("href")])

Ok now we have our list of jobs and a url for each one. Let’s tell the browser to go to each job page and get the contact information so we can send a email to the employer. We can do that by looping through the new list we just made jobLinks.

for link in links: #We take the job title and url and add it to a list so we have a list of lists jobLinks.append([link.text,link.get_attribute("href")])

for link in jobLinks: browser.get(link[1]) if len(browser.find_elements(By.CSS_SELECTOR, '.reply_button')):#here we check if there is an apply button with a email we can apply to. browser.find_elements(By.CSS_SELECTOR, '.reply_button')[0].click()#here we click the reply button time.sleep(5)#tells the program to wait 5 seconds email = browser.find_elements(By.CSS_SELECTOR, '.anonemail')[0].text #here we extract the email address title = browser.find_elements(By.CSS_SELECTOR, '#titletextonly')[0].text #here we extract the job title again browser.implicitly_wait(40)

Ok now that we can easily find the jobs we want and go to each page we need to send an email to complete this function but before we need to be able to send out the emails. For that we will be using smtplib along with mail which we imported at the start. We will make a new function just to send emails. Lets add this before our getJobs function we will call it sendMail(). We will re-use most of the old parameters from the getJobs function.

for link in links: #We take the job title and url and add it to a list so we have a list of lists
jobLinks.append([link.text,link.get_attribute("href")])

for link in jobLinks: browser.get(link[1]) if len(browser.find_elements(By.CSS_SELECTOR, '.reply_button')):#here we check if there is an apply button with a email we can apply to. browser.find_elements(By.CSS_SELECTOR, '.reply_button')[0].click()#here we click the reply button time.sleep(5)#tells the program to wait 5 seconds email = browser.find_elements(By.CSS_SELECTOR, '.anonemail')[0].text #here we extract the email address title = browser.find_elements(By.CSS_SELECTOR, '#titletextonly')[0].text #here we extract the job title again sendMail(title,email,res,un,pw,cover)#send the email browser.implicitly_wait(40)

Now we need to add in our cover letter we will just use a long string.

coverLetter = """I am writing with reference to your Cashier position listed recently on Craigslist. This position appeals to me because of my strong interest in customer service and cash handling. The skills and knowledge I have gained through my education and volunteer experiences will help me perform extremely well for your organization.

As you will note from my enclosed resume, some strengths of mine include:

❖ Well versed in operating cash registers, optical price scanners and computers ❖ Demonstrated ability to give every customer immediate and undivided attention ❖ Skilled in following through on all customer questions and requests ❖ Able to keep department supplies filled and maintained ❖ Proven record of collecting payments accurately for purchases and make change ❖ Track record of maintaining secure custody of all cash, the cash till and any additional items such as register key

The above mentioned attributes combined with my enthusiasm, excellent communication skills and proficiency in MS Word and Excel, make me a perfect candidate for this position. The enclosed resume contains complete details about my cashiering skills and qualifications.

As a passionate and trustworthy cashier, I would like to meet with you to discuss how my skills fit perfectly with your requirements. If you require any additional information in the interim, please give me a call at (716) 777 - 7777 or send me an email at youremail@gmail.com.

Thank you for your time and consideration. I look forward to hearing from you soon.Sincerely,

Millennial Dave"""

Now all we have to do is call getJobs() with our parameters and our script will apply to jobs for us based on what searched.

for link in links: #We take the job title and url and add it to a list so we have a list of lists
jobLinks.append([link.text,link.get_attribute("href")])

for link in jobLinks: browser.get(link[1]) if len(browser.find_elements(By.CSS_SELECTOR, '.reply_button')):#here we check if there is an apply button with a email we can apply to. browser.find_elements(By.CSS_SELECTOR, '.reply_button')[0].click()#here we click the reply button time.sleep(5)#tells the program to wait 5 seconds email = browser.find_elements(By.CSS_SELECTOR, '.anonemail')[0].text #here we extract the email address title = browser.find_elements(By.CSS_SELECTOR, '#titletextonly')[0].text #here we extract the job title again sendMail(title,email,res,un,pw,cover)#send the email browser.implicitly_wait(40)

coverLetter = """I am writing with reference to your Cashier position listed recently on Craigslist. This position appeals to me because of my strong interest in customer service and cash handling. The skills and knowledge I have gained through my education and volunteer experiences will help me perform extremely well for your organization.

As you will note from my enclosed resume, some strengths of mine include:

❖ Well versed in operating cash registers, optical price scanners and computers ❖ Demonstrated ability to give every customer immediate and undivided attention ❖ Skilled in following through on all customer questions and requests ❖ Able to keep department supplies filled and maintained ❖ Proven record of collecting payments accurately for purchases and make change ❖ Track record of maintaining secure custody of all cash, the cash till and any additional items such as register key

The above mentioned attributes combined with my enthusiasm, excellent communication skills and proficiency in MS Word and Excel, make me a perfect candidate for this position. The enclosed resume contains complete details about my cashiering skills and qualifications.

As a passionate and trustworthy cashier, I would like to meet with you to discuss how my skills fit perfectly with your requirements. If you require any additional information in the interim, please give me a call at (716) 777 - 7777 or send me an email at youremail@gmail.com.

Thank you for your time and consideration. I look forward to hearing from you soon.Sincerely,