mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 00:47:15 +08:00
detect no job after last page load - restart browser after this happen
This commit is contained in:
+54
-41
@@ -75,7 +75,7 @@ async function mainLoop () {
|
|||||||
);
|
);
|
||||||
await sleepWithRandomDelay(2000)
|
await sleepWithRandomDelay(2000)
|
||||||
|
|
||||||
const { targetJobElProxy, targetJobIndex } = await new Promise(async (resolve) => {
|
const { targetJobElProxy, targetJobIndex } = await new Promise(async (resolve, reject) => {
|
||||||
// job list
|
// job list
|
||||||
const recommendJobListElProxy = await page.$('.job-list-container .rec-job-list')
|
const recommendJobListElProxy = await page.$('.job-list-container .rec-job-list')
|
||||||
|
|
||||||
@@ -85,7 +85,9 @@ async function mainLoop () {
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
let targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
let targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
||||||
while (targetJobIndex < 0) {
|
let hasReachLastPage = false
|
||||||
|
|
||||||
|
while (targetJobIndex < 0 && !hasReachLastPage) {
|
||||||
// fetch new
|
// fetch new
|
||||||
const recommendJobListElBBox = await recommendJobListElProxy.boundingBox()
|
const recommendJobListElBBox = await recommendJobListElProxy.boundingBox()
|
||||||
const windowInnerHeight = await page.evaluate('window.innerHeight')
|
const windowInnerHeight = await page.evaluate('window.innerHeight')
|
||||||
@@ -101,6 +103,12 @@ async function mainLoop () {
|
|||||||
await page.mouse.wheel({deltaY: increase});
|
await page.mouse.wheel({deltaY: increase});
|
||||||
await sleep(1)
|
await sleep(1)
|
||||||
}
|
}
|
||||||
|
hasReachLastPage = await page.evaluate(`
|
||||||
|
!(document.querySelector('.job-recommend-main')?.__vue__?.hasMore)
|
||||||
|
`)
|
||||||
|
if (hasReachLastPage) {
|
||||||
|
console.log(`Arrive the terminal of the job list.`)
|
||||||
|
}
|
||||||
|
|
||||||
await sleep(3000)
|
await sleep(3000)
|
||||||
jobListData = await page.evaluate(
|
jobListData = await page.evaluate(
|
||||||
@@ -111,6 +119,12 @@ async function mainLoop () {
|
|||||||
targetJobIndex = targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
targetJobIndex = targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (targetJobIndex < 0 && hasReachLastPage) {
|
||||||
|
// has reach last page and not find target job
|
||||||
|
reject(new Error('CANNOT_FIND_EXCEPT_JOB'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const recommendJobItemList = await recommendJobListElProxy.$$('ul.rec-job-list > li')
|
const recommendJobItemList = await recommendJobListElProxy.$$('ul.rec-job-list > li')
|
||||||
resolve(
|
resolve(
|
||||||
{
|
{
|
||||||
@@ -144,53 +158,52 @@ async function mainLoop () {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await sleepWithRandomDelay(2000)
|
await sleepWithRandomDelay(2000)
|
||||||
}
|
const jobData = await page.evaluate('document.querySelector(".job-detail-box").__vue__.data')
|
||||||
|
|
||||||
const jobData = await page.evaluate('document.querySelector(".job-detail-box").__vue__.data')
|
const startChatButtonInnerHTML = await page.evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()')
|
||||||
|
if (startChatButtonInnerHTML === '立即沟通') {
|
||||||
|
const startChatButtonProxy = await page.$('.job-detail-box .op-btn.op-btn-chat')
|
||||||
|
await startChatButtonProxy.click()
|
||||||
|
|
||||||
const startChatButtonInnerHTML = await page.evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()')
|
const addFriendResponse = await page.waitForResponse(
|
||||||
if (startChatButtonInnerHTML === '立即沟通') {
|
response => {
|
||||||
const startChatButtonProxy = await page.$('.job-detail-box .op-btn.op-btn-chat')
|
if (
|
||||||
await startChatButtonProxy.click()
|
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/friend/add.json') && response.url().includes(`jobId=${jobData.jobInfo.encryptId}`)
|
||||||
|
) {
|
||||||
const addFriendResponse = await page.waitForResponse(
|
return true
|
||||||
response => {
|
}
|
||||||
if (
|
return false
|
||||||
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/friend/add.json') && response.url().includes(`jobId=${jobData.jobInfo.encryptId}`)
|
|
||||||
) {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
);
|
||||||
}
|
try {
|
||||||
);
|
const res = await addFriendResponse.json()
|
||||||
try {
|
|
||||||
const res = await addFriendResponse.json()
|
|
||||||
|
|
||||||
if (res.code !== 0) {
|
if (res.code !== 0) {
|
||||||
console.err(res)
|
console.err(res)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
// console.warn(err)
|
// console.warn(err)
|
||||||
} finally {
|
} finally {
|
||||||
//#region TODO: temporary work with legacy logic
|
//#region TODO: temporary work with legacy logic
|
||||||
await sleep(500)
|
await sleep(500)
|
||||||
const continueChatButtonProxy = await page.$('.greet-boss-dialog .greet-boss-footer .sure-btn')
|
const continueChatButtonProxy = await page.$('.greet-boss-dialog .greet-boss-footer .sure-btn')
|
||||||
|
|
||||||
await continueChatButtonProxy.click()
|
await continueChatButtonProxy.click()
|
||||||
//#endregion
|
//#endregion
|
||||||
await sleepWithRandomDelay(2500)
|
await sleepWithRandomDelay(2500)
|
||||||
if (page.url().startsWith('https://www.zhipin.com/web/geek/chat')) {
|
if (page.url().startsWith('https://www.zhipin.com/web/geek/chat')) {
|
||||||
await sleepWithRandomDelay(3000)
|
await sleepWithRandomDelay(3000)
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.goBack(),
|
page.goBack(),
|
||||||
])
|
])
|
||||||
await sleepWithRandomDelay(1000)
|
await sleepWithRandomDelay(1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user