This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
const fs = require("fs"); | |
const constants = require("./../util/constants.js"); | |
const emailModule = require("./send-email.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const browser = await puppeteer.launch({ | |
headless: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const page = await browser.newPage(); | |
await page.goto(constants.STATE_FARM_URI); | |
await page.click(constants.STATE_FARM_LOC_DRPDWN); | |
await page.click(constants.STATE_FARM_TX_RD_BTN); | |
await page.click(constants.STATE_FARM_SRCH_FRM); | |
await page.keyboard.type(constants.STATE_FARM_SRCH_TECH); | |
await page.click(constants.STATE_FARM_SUBMIT_BTN); | |
await page.waitFor(2000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = Object.freeze({ | |
STATE_FARM_URI : "https://statefarm.csod.com/ats/careersite/search.aspx?site=1&c=statefarm", | |
STATE_FARM_LOC_DRPDWN : "#ctl00_siteContent_widgetLayout_rptWidgets_ctl03_widgetContainer_ctl00_rptCustomFields_ctl02_customFieldWrapper > button", | |
STATE_FARM_TX_RD_BTN : "body > div > ul > li:nth-child(46) > label > span", | |
STATE_FARM_SRCH_FRM : "#ctl00_siteContent_widgetLayout_rptWidgets_ctl03_widgetContainer_ctl00_rptCustomFields_ctl00_customFieldWrapper_ctl00_txtValue", | |
STATE_FARM_SRCH_TECH : "technology", | |
STATE_FARM_SUBMIT_BTN : "#ctl00_siteContent_widgetLayout_rptWidgets_ctl03_widgetContainer_ctl00_btnSearch", | |
SUCCESS_STMT : "File successfully written! - Check your project directory for the state-farm-jobs.txt file", | |
STATE_FARM_JOB_SELECTOR : "#ctl00_siteContent_widgetLayout_rptWidgets_ctl03_widgetContainer_ctl00_ctl00 > ul > li:nth-child(INDEX)", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numPages = await getNumPages(page); | |
console.log('Number of pages: ', numPages); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getNumPages(page) { | |
const PAGE_CONTAINTER_SELECTOR = constants.STATE_FARM_PAGE_CONTAINTER_SELECTOR; | |
let pageCount = await page.evaluate((sel) => { | |
let defaultCount = 1; | |
let pageContainer = document.querySelector(sel); | |
let allPages = pageContainer.getElementsByClassName("pagerLink"); | |
if (allPages.length > 0) { | |
return allPages.length; | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (let h = 1; h <= numPages; h++) { | |
console.log("Page Number : " + h); | |
let jobListLength = await page.evaluate((sel) => { | |
let jobSelectorID = document.getElementById(sel); | |
let jobSelectorTagName = jobSelectorID.getElementsByTagName("li"); | |
return jobSelectorTagName.length; | |
}, JOB_SELECTOR_ID); | |
for (let i = 1; i <= jobListLength; i++) { | |
let jobSelector = LIST_JOB_SELECTOR.replace("INDEX", i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let jobListLength = await page.evaluate((sel) => { | |
let jobSelectorID = document.getElementById(sel); | |
let jobSelectorTagName = jobSelectorID.getElementsByTagName("li"); | |
return jobSelectorTagName.length; | |
}, JOB_SELECTOR_ID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (let i = 1; i <= jobListLength; i++) { | |
let jobSelector = LIST_JOB_SELECTOR.replace("INDEX", i) | |
let jobListing = await page.evaluate((sel) => { | |
return document.querySelector(sel).innerText; | |
}, jobSelector); | |
arrayJobResults.push(jobListing); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (numPages != 1) { | |
await page.click(constants.STATE_FARM_NEXT_PAGE_SELECTOR); | |
await page.waitFor(2000); | |
} | |
} |
OlderNewer