mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 08:27:13 +08:00
WIP: finish the filter logic of '薪资待遇', '工作经验', '学历要求', '公司规模' TODO: the filter logic of '公司行业'
This commit is contained in:
@@ -13,6 +13,14 @@ import { setDomainLocalStorage } from '@geekgeekrun/utils/puppeteer/local-storag
|
|||||||
|
|
||||||
import { readConfigFile, writeStorageFile, ensureConfigFileExist, readStorageFile, ensureStorageFileExist } from './runtime-file-utils.mjs'
|
import { readConfigFile, writeStorageFile, ensureConfigFileExist, readStorageFile, ensureStorageFileExist } from './runtime-file-utils.mjs'
|
||||||
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
||||||
|
import { default as jobFilterConditions } from './internal-config/job-filter-conditions-20241002.json'
|
||||||
|
const jobFilterConditionsMapByCode = {}
|
||||||
|
Object.values(jobFilterConditions).forEach(arr => {
|
||||||
|
arr.forEach(option => {
|
||||||
|
jobFilterConditionsMapByCode[option.code] = option
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
ensureConfigFileExist()
|
ensureConfigFileExist()
|
||||||
ensureStorageFileExist()
|
ensureStorageFileExist()
|
||||||
|
|
||||||
@@ -154,6 +162,13 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
const optionKaPrefixes = ['sel-job-rec-salary-', 'sel-job-rec-exp-', 'sel-job-rec-degree-', 'sel-job-rec-scale-']
|
const optionKaPrefixes = ['sel-job-rec-salary-', 'sel-job-rec-exp-', 'sel-job-rec-degree-', 'sel-job-rec-scale-']
|
||||||
const conditionArr = [salaryList, experienceList, degreeList, scaleList]
|
const conditionArr = [salaryList, experienceList, degreeList, scaleList]
|
||||||
|
|
||||||
|
console.log('current filter condition----')
|
||||||
|
for (let i = 0; i < placeholderTexts.length; i++) {
|
||||||
|
const text = placeholderTexts[i]
|
||||||
|
const condition = conditionArr[i]
|
||||||
|
console.log(`${text}:`, condition.length === 0 ? '不限' : condition.map(code => jobFilterConditionsMapByCode[code]?.name ?? code).join(',') )
|
||||||
|
}
|
||||||
|
console.log('----------------------------')
|
||||||
for(let i = 0; i < placeholderTexts.length; i++) {
|
for(let i = 0; i < placeholderTexts.length; i++) {
|
||||||
const placeholderText = placeholderTexts[i]
|
const placeholderText = placeholderTexts[i]
|
||||||
const filterDropdownProxy = await (async () => {
|
const filterDropdownProxy = await (async () => {
|
||||||
@@ -168,8 +183,9 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentFilterConditions = conditionArr[i];
|
||||||
const filterDropdownCssList = await filterDropdownProxy.evaluate(el => Array.from(el.classList));
|
const filterDropdownCssList = await filterDropdownProxy.evaluate(el => Array.from(el.classList));
|
||||||
if (!filterDropdownCssList.includes('is-select') && !conditionArr[i].length) {
|
if (!filterDropdownCssList.includes('is-select') && !currentFilterConditions.length) {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
const filterDropdownElBBox = await filterDropdownProxy.boundingBox()
|
const filterDropdownElBBox = await filterDropdownProxy.boundingBox()
|
||||||
@@ -180,14 +196,54 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
await sleepWithRandomDelay(500)
|
await sleepWithRandomDelay(500)
|
||||||
|
|
||||||
const optionKaPrefix = optionKaPrefixes[i]
|
const optionKaPrefix = optionKaPrefixes[i]
|
||||||
for(let j = 0; j < conditionArr[i].length; j++) {
|
if (!currentFilterConditions.length) {
|
||||||
const optionValue = conditionArr[i][j]
|
// select 不限 immediately
|
||||||
await sleepWithRandomDelay(500)
|
const buxianOptionElProxy = await page.$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li[ka="${optionKaPrefix}${0}"]`)
|
||||||
const optionElProxy = await page.$(`li[ka="${optionKaPrefix}${optionValue}"]`)
|
await buxianOptionElProxy.click()
|
||||||
if (!optionElProxy) {
|
} else {
|
||||||
continue;
|
//#region uncheck options perviously checked but not existed in current filter.
|
||||||
|
const activeOptionElAtCurrentFilterProxyList = await page.$$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li.active[ka^="${optionKaPrefix}"]`)
|
||||||
|
const activeOptionValues = (await Promise.all(
|
||||||
|
activeOptionElAtCurrentFilterProxyList.map(elProxy => {
|
||||||
|
return elProxy.evaluate((el) => {
|
||||||
|
return el.getAttribute('ka')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)).map(it => it.replace(optionKaPrefix, '')).map(Number)
|
||||||
|
if (placeholderText !== '薪资待遇') {
|
||||||
|
for(let i = 0; i < activeOptionValues.length; i++) {
|
||||||
|
const activeValue = activeOptionValues[i]
|
||||||
|
const activeOptionElProxy = activeOptionElAtCurrentFilterProxyList[i]
|
||||||
|
if (!currentFilterConditions.includes(activeValue)) {
|
||||||
|
await activeOptionElProxy.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await optionElProxy.click()
|
//#endregion
|
||||||
|
//#region only click the one which we need check, don't change already checked.
|
||||||
|
const conditionToCheck = currentFilterConditions.filter(it => {
|
||||||
|
return !activeOptionValues.includes(it)
|
||||||
|
})
|
||||||
|
for(let j = 0; j < conditionToCheck.length; j++) {
|
||||||
|
const optionValue = conditionToCheck[j]
|
||||||
|
await sleepWithRandomDelay(500)
|
||||||
|
const optionElProxy = await page.$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li[ka="${optionKaPrefix}${optionValue}"]`)
|
||||||
|
if (!optionElProxy) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await optionElProxy.click()
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
//#region move out dropdown entry to make dropdown hidden
|
||||||
|
const navBarLogoElProxy = await page.$(`[ka="header-home-logo"]`)
|
||||||
|
if (navBarLogoElProxy) {
|
||||||
|
const navBarLogoElBBox = await navBarLogoElProxy.boundingBox()
|
||||||
|
await page.mouse.move(
|
||||||
|
navBarLogoElBBox.x + navBarLogoElBBox.width / 2,
|
||||||
|
navBarLogoElBBox.y + navBarLogoElBBox.height / 2,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
await sleepWithRandomDelay(500)
|
await sleepWithRandomDelay(500)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user