deal with first job is target job so that fix a endless async loop

This commit is contained in:
bossgeekgo
2024-02-11 17:18:28 +08:00
parent a1ce4fbab9
commit e9bba46b50
+16 -13
View File
@@ -158,7 +158,7 @@ async function mainLoop (hooks) {
} }
) )
}) })
if (targetJobIndex > 0) { if (targetJobIndex >= 0) {
// scroll that target element into view // scroll that target element into view
await page.evaluate(` await page.evaluate(`
targetEl = document.querySelector("ul.rec-job-list").children[${targetJobIndex}] targetEl = document.querySelector("ul.rec-job-list").children[${targetJobIndex}]
@@ -170,19 +170,22 @@ async function mainLoop (hooks) {
await sleepWithRandomDelay(200) await sleepWithRandomDelay(200)
// click that element if (targetJobIndex === 0) {
await targetJobElProxy.click() } else {
await page.waitForResponse( // click that element
response => { await targetJobElProxy.click()
if ( await page.waitForResponse(
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/job/detail.json') response => {
) { if (
return true response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/job/detail.json')
) {
return true
}
return false
} }
return false );
} 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()') const startChatButtonInnerHTML = await page.evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()')