Beispiel #1
0
    def apply(self, job):
        '''apply to job, create and commit job object to db, and return job object.
        return False if the job link is invalid.'''

        job_profile = CommonFuncs.get_job_profile()

        if not CommonFuncs.is_valid_url(job):
            return False

        self.driver.get(job)

        btns = self.driver.find_elements(By.TAG_NAME, 'button')
        apply_form_opened = False
        for btn in btns:
            if "Apply" in btn.text:
                btn.click()
                apply_form_opened = True
                break

        # CREATE JOB OBJECT
        new_job = Job()
        new_job.app_date = datetime.now()
        new_job.link_to_job = job
        try:
            new_job.job_title = self.driver.find_element(
                By.CLASS_NAME, 'job_title').text
        except:
            pass
        try:
            company_link = self.driver.find_element(
                By.CLASS_NAME,
                'hiring_company_text').find_element(By.TAG_NAME, 'a')
            new_job.company = company_link.text
            new_job.company_site = company_link.get_attribute('href')
        except:
            pass
        try:
            new_job.location = self.driver.find_element(
                By.CLASS_NAME, 'location_text').text
        except:
            pass
        new_job.job_site = CommonFuncs.fetch_domain_name(job)
        new_job.applied = False

        try:
            name = self.driver.find_element(By.ID, 'name')
            name.clear()
            name.send_keys(job_profile.applicant_name)
        except:
            pass
        try:
            email = self.driver.find_element_by_id('email_address')
            email.clear()
            email.send_keys(job_profile.email)
        except:
            pass
        try:
            phone = self.driver.find_element_by_id('phone_number')
            phone.clear()
            phone.send_keys(job_profile.phone_number)
        except:
            pass
        resume_file_path = None
        try:
            resume_file_path = eval(job_profile.resume)[0]
            resume_file_path = resume_file_path.replace('/', '//')
            self.driver.find_element_by_id('resume'). \
                send_keys(resume_file_path)
        except:
            pass
        try:
            self.driver.find_element(By.ID, 'contact_create_form').submit()
            new_job.applied = True
        except:
            pass

        # 1-click apply does not have an edit resume button, so the resume must be changed after clicking the button
        if not apply_form_opened:  # if the form did not open try to click the 1-click apply btn
            links = self.driver.find_elements(By.PARTIAL_LINK_TEXT, 'pply')
            for link in links:
                try:
                    link.click()
                    self.driver.get(
                        JOB_SITE_LINKS['Ziprecruiter']['applied_jobs'])
                    applied_jobs_list = self.driver\
                        .find_element(By.CLASS_NAME, 'appliedJobsList')\
                        .find_elements(By.TAG_NAME, 'li')
                    last_job_applied_to = applied_jobs_list[0]
                    resume_edit_item = last_job_applied_to\
                        .find_element(By.CLASS_NAME, 'dropdown')\
                        .find_element(By.TAG_NAME, 'ul')\
                        .find_elements(By.TAG_NAME, 'li')[1] \
                        .find_element(By.TAG_NAME, 'a')
                    resume_edit_link = resume_edit_item.get_attribute('href')
                    self.driver.get(resume_edit_link)
                    self.driver.find_element(
                        By.ID, 'resumeInput').send_keys(resume_file_path)
                    self.driver.find_element(By.ID, 'replaceResume').submit()
                    new_job.applied = True
                    break
                except:
                    pass

        try:
            self.driver.find_element(By.ID, 'zip_resume_verify').click()
        except:
            pass
        try:
            sleep(3)
            while True:
                resumeLoading = self.driver.find_element(
                    By.ID, 'zipresumeLoading')
                if not resumeLoading.is_displayed():
                    break
                sleep(1)
        except:
            pass
        try:
            self.driver.find_element(By.ID, 'zip_resume_verify').click()
        except:
            pass

        return new_job


# if __name__ =='__main__':
#     with CommonFuncs.get_driver(visible=True) as driver:
#         z=Ziprecruiter_Bot(driver=driver)
#         jobsiteaccount = JobSiteAccount()
#         jobsiteaccount.username = "******"
#         jobsiteaccount.password = "******"
#         z.login(jobsiteaccount)
#         z.apply(n)
Beispiel #2
0
    def apply(self, job):
        '''apply to job, create and commit job object to db, and return job object.'''

        job_profile = None
        with CommonFuncs.get_db() as db:  # if no job profile, return
            try:
                job_profile = db.query(JobProfile).one()
            except:
                return

        # NAVIGATE TO JOB PAGE
        self.driver.get(job)

        # CREATE JOB OBJECT
        new_job = Job()
        new_job.app_date = datetime.now()
        new_job.link_to_job = job
        try:
            new_job.job_title = self.driver.find_element(
                By.CLASS_NAME, 'jobtitle').text
            new_job.company = self.driver.find_element(By.CLASS_NAME,
                                                       'company').text
            new_job.location = self.driver.find_element(
                By.CLASS_NAME, 'location').text
        except:
            pass
        new_job.job_site = CommonFuncs.fetch_domain_name(job)
        new_job.appled = False

        try:
            self.driver.implicitly_wait(1)
            try:
                self.driver.find_element_by_class_name(
                    'indeed-apply-button').click()
            except:
                return new_job
            CommonFuncs.switch_frames(self.driver,
                                      'iframe[name$=modal-iframe]')

            # RESUME UPLOAD
            try:
                resume_file = eval(job_profile.resume)[0]
                self.driver.implicitly_wait(2)
                resume_file = resume_file.replace('/', '//')
                self.driver.find_element_by_id('resume').send_keys(resume_file)
            except:
                return new_job

            # UNIQUE(optional) COVER LETTER
            try:
                cover_letter_text = CommonFuncs.extract_text(
                    eval(job_profile.cover_letter)[0])
                if '{{company_name}}' in cover_letter_text:
                    cover_letter_text = cover_letter_text.replace(
                        '{{company_name}}', job['company'])
                if '{{job_title}}' in cover_letter_text:
                    cover_letter_text = cover_letter_text.replace(
                        '{{job_title}}', job['jobtitle'])

                cl_box = self.driver.find_element_by_tag_name('textarea')
                cl_box.clear()
                self.driver.implicitly_wait(1)
                for c in cover_letter_text:  # send characters one at a time (otherwise some are consumed)
                    cl_box.send_keys(c)
            except:
                pass

            # SUPPORTING DOCUMENTATION - if requested and available from user
            try:
                isdoc = 1
                supp_docs = []
                for sdoc in eval(job_profile.supporting_docs):
                    self.driver.find_element_by_id('multattach' +
                                                   str(isdoc)).send_keys(sdoc)
                    isdoc += 1
            except:
                pass

            # FILL OUT OTHER QUESTIONS & SUBMIT
            try:
                # FILL IN FULL NAME
                try:
                    self.driver.find_element_by_id('applicant.name').send_keys(
                        job_profile.applicant_name)
                except:
                    pass
                # FIRST NAME
                try:
                    self.driver.find_element_by_id('applicant.firstName').\
                        send_keys(job_profile.applicant_name.split(' ')[0])
                except:
                    pass
                # LAST NAME
                try:
                    self.driver.find_element_by_id('applicant.lastName').\
                        send_keys(job_profile.applicant_name.split(' ')[1])
                except:
                    pass
                # PHONE NUMBER
                try:
                    self.driver.find_element_by_id('applicant.phoneNumber').\
                        send_keys(job_profile.phone_number)
                except:
                    pass
                # ADDRESS
                try:
                    self.driver.find_element_by_xpath('//*[@data-prefill-id="q_basic_0_street_address"]')\
                        .send_keys(job_profile.your_address)
                except:
                    pass
                # CITY
                try:
                    self.driver.find_element_by_xpath('//*[@data-prefill-id="q_basic_0_city"]')\
                        .send_keys(job_profile.your_city)
                except:
                    pass

                # QUESTION AND ANSWER
                self.driver.find_element_by_id('apply').click()
                self.driver.implicitly_wait(1)
                new_job.applied = True
            except (NoSuchElementException, ElementNotVisibleException
                    ):  # catch event where there is no continue
                self.driver.find_element_by_id('apply').click()
                self.driver.implicitly_wait(1)
                new_job.applied = True
            finally:
                self.driver.switch_to.window(self.driver.window_handles[0])
        except (NoSuchElementException, ElementNotVisibleException):
            new_job.appled = False

        return new_job
Beispiel #3
0
    def apply(self, job):
        '''apply to the job and store in db. return the job object.'''

        job_profile = None
        with CommonFuncs.get_db() as db:  # if no job profile, return
            try:
                job_profile = db.query(JobProfile).one()
            except:
                return

        self.driver.get(job)  # navigate to job page

        # build job object
        new_job = Job()
        new_job.app_date = datetime.now()
        new_job.link_to_job = job
        new_job.job_title = self.driver.find_element_by_xpath(
            '//*[@id="frame"]/div[4]/div/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[2]/h1'
        ).text
        new_job.job_site = CommonFuncs.fetch_domain_name(
            self.driver.current_url)
        new_job.applied = False  # default

        # GET EMPLOYER NAME
        try:
            employer_name = self.driver.find_element_by_class_name(
                'job_emp_details').find_element_by_tag_name('a').text
            new_job.company = employer_name
        except:
            pass

        # GET LOCATION
        try:
            other_data = self.driver.find_elements_by_class_name('job-bfields')
            for datum in other_data:
                if "location" in datum.find_element_by_class_name(
                        'label').text.lower():
                    job_location = datum.find_element_by_class_name(
                        'widget').text
                    new_job.location = job_location
                    break
        except:
            pass

        # GET CONTACT INFO - if available
        try:
            contact_block = self.driver.find_element_by_id('sb_contactinfo')
            contents = contact_block.text.split('\n')
            new_job.contact_name = contents[1]
            for item in contents:
                if "@" in item:
                    new_job.contact_email = item
                elif "http" in item:
                    new_job.company_site = item
        except:
            pass

        # OPEN APPLICATION FORM
        try:
            job_apply_button = self.driver.find_element_by_id('job_send_docs')
            job_apply_button.click()
            docs_used = []
            # make doc selections
            doc_fields = [
                'resume', 'cover_letter', 'writing_sample', 'transcript'
            ]
            supporting_docs = []
            for doc_field in doc_fields:
                try:
                    select = Select(
                        self.driver.find_element_by_name(
                            "dnf_class_values[non_ocr_job_resume][%s]" %
                            doc_field))
                    if doc_field == "resume":
                        select.select_by_index(0)
                    else:
                        select.select_by_index(
                            1)  # select the first available cover letter
                except:
                    pass

            # SUBMIT APPLICATION
            try:
                self.driver.find_element_by_xpath(
                    "//*[@id='job_resume_form']").find_element_by_name(
                        "dnf_opt_submit").click()
                new_job.applied = True
            except:
                new_job.appled = False
        except:
            new_job.appled = False

        return new_job