mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 08:57:24 +08:00
refactor code about collect job info
This commit is contained in:
@@ -49,64 +49,62 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleJobDetailPage({ encryptJobId } = { encryptJobId: null }) {
|
// FIXME: might not work
|
||||||
Promise.resolve()
|
async function handleJobDetailPage({ encryptJobId } = { encryptJobId: null }) {
|
||||||
.then(async () => {
|
if (!encryptJobId) {
|
||||||
if (!encryptJobId) {
|
return
|
||||||
return
|
}
|
||||||
}
|
try {
|
||||||
try {
|
await page.waitForFunction(
|
||||||
await page.waitForFunction(
|
({ encryptJobId }) => {
|
||||||
({ encryptJobId }) => {
|
return (
|
||||||
return (
|
location.href.startsWith(`https://www.zhipin.com/job_detail/${encryptJobId}`) &&
|
||||||
location.href.startsWith(`https://www.zhipin.com/job_detail/${encryptJobId}`) &&
|
(!!document.querySelector('#main .job-banner') ||
|
||||||
document.readyState === 'complete'
|
!!document.documentElement.innerText?.includes(`您访问的页面不存在`))
|
||||||
)
|
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
{ encryptJobId }
|
|
||||||
)
|
)
|
||||||
const htmlContent = await page.content()
|
},
|
||||||
if (htmlContent) {
|
undefined,
|
||||||
const $ = cheerio.load(htmlContent)
|
{ encryptJobId }
|
||||||
const [jobBannerEl] = $('#main .job-banner') ?? []
|
)
|
||||||
if (!jobBannerEl) {
|
const htmlContent = await page.content()
|
||||||
console.log(`access might be blocked`)
|
if (htmlContent) {
|
||||||
if (
|
const $ = cheerio.load(htmlContent)
|
||||||
htmlContent.includes(`您访问的页面不存在`) ||
|
const [jobBannerEl] = $('#main .job-banner') ?? []
|
||||||
location.href === `https://www.zhipin.com/`
|
if (!jobBannerEl) {
|
||||||
) {
|
console.log(`access might be blocked`)
|
||||||
await saveJobHireStatusRecord(await dbInitPromise, {
|
if (
|
||||||
encryptJobId,
|
htmlContent.includes(`您访问的页面不存在`) ||
|
||||||
hireStatus: JobHireStatus.DELETED,
|
location.href === `https://www.zhipin.com/`
|
||||||
lastSeenDate: new Date()
|
) {
|
||||||
})
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
}
|
encryptJobId,
|
||||||
|
hireStatus: JobHireStatus.DELETED,
|
||||||
|
lastSeenDate: new Date()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const [jobStatusTextEl] = $('#main .job-banner .job-status') ?? []
|
||||||
|
if (jobStatusTextEl) {
|
||||||
|
const jobStatusText = $(jobStatusTextEl).text()?.trim() ?? ''
|
||||||
|
if ([`职位已关闭`].includes(jobStatusText)) {
|
||||||
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
|
encryptJobId,
|
||||||
|
hireStatus: JobHireStatus.CLOSED,
|
||||||
|
lastSeenDate: new Date()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
const [jobStatusTextEl] = $('#main .job-banner .job-status') ?? []
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
if (jobStatusTextEl) {
|
encryptJobId,
|
||||||
const jobStatusText = $(jobStatusTextEl).text()?.trim() ?? ''
|
hireStatus: JobHireStatus.HIRING,
|
||||||
if ([`职位已关闭`].includes(jobStatusText)) {
|
lastSeenDate: new Date()
|
||||||
await saveJobHireStatusRecord(await dbInitPromise, {
|
})
|
||||||
encryptJobId,
|
|
||||||
hireStatus: JobHireStatus.CLOSED,
|
|
||||||
lastSeenDate: new Date()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
await saveJobHireStatusRecord(await dbInitPromise, {
|
|
||||||
encryptJobId,
|
|
||||||
hireStatus: JobHireStatus.HIRING,
|
|
||||||
lastSeenDate: new Date()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch(() => void 0)
|
} catch {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.url().match(/^https:\/\/www.zhipin.com\/job_detail\/(.+)\.html/)) {
|
if (page.url().match(/^https:\/\/www.zhipin.com\/job_detail\/(.+)\.html/)) {
|
||||||
@@ -200,7 +198,7 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
)
|
)
|
||||||
const requestBody = new URLSearchParams(response.request().postData())
|
const requestBody = new URLSearchParams(response.request().postData())
|
||||||
|
|
||||||
const securityIdInRequest = requestBody.get("securityId")
|
const securityIdInRequest = requestBody.get('securityId')
|
||||||
const currentJobSecurityId = currentJobData?.securityId
|
const currentJobSecurityId = currentJobData?.securityId
|
||||||
|
|
||||||
if (securityIdInRequest !== currentJobSecurityId) {
|
if (securityIdInRequest !== currentJobSecurityId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user