when arrive the terminal of the recommend job list, reload page and continue trying to find except job

This commit is contained in:
bossgeekgo
2024-02-09 19:22:59 +08:00
parent 21119e346b
commit 6e8f6cbf81
+13 -1
View File
@@ -50,7 +50,7 @@ async function mainLoop () {
const recommendJobLink = (await page.$('[ka=header-job-recommend]'))
await recommendJobLink.click()
while (true) {
afterPageLoad: while (true) {
await sleepWithRandomDelay(3000)
const expectJobList = (await page.evaluate(`
@@ -75,6 +75,7 @@ async function mainLoop () {
);
await sleepWithRandomDelay(2000)
try {
const { targetJobElProxy, targetJobIndex } = await new Promise(async (resolve, reject) => {
// job list
const recommendJobListElProxy = await page.$('.job-list-container .rec-job-list')
@@ -205,6 +206,17 @@ async function mainLoop () {
} else {
}
}
} catch (err) {
if (err instanceof Error && err.message === 'CANNOT_FIND_EXCEPT_JOB') {
await Promise.all([
page.reload(),
page.waitForNavigation()
])
continue afterPageLoad;
} else {
throw err
}
}
}
// ;await browser.close()