Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

超出索引范围,脚本死循环 #2

Closed
Kwaiyu opened this issue Jan 9, 2024 · 3 comments
Closed

超出索引范围,脚本死循环 #2

Kwaiyu opened this issue Jan 9, 2024 · 3 comments

Comments

@Kwaiyu
Copy link

Kwaiyu commented Jan 9, 2024

控制台输出:

在索引 33155 处找不到工作。
职位描述信息/n:null
在索引 33156 处找不到工作。
职位描述信息/n:null
在索引 33157 处找不到工作。
职位描述信息/n:null
在索引 33158 处找不到工作。
职位描述信息/n:null
在索引 33159 处找不到工作。

可以看出BOSS网页上是根据当前索引值加载完成后,才会继续加后面的索引值:如当前在索引406,加载到420索引就不会在继续加载
image

当前如果到420,才会继续加载到435
image

那么脚本在10秒内如果没有找到这个索引项目,并且没有找到描述信息节点并获取文字就会走到异常分支。
这个该怎么优化呢?

@laura-xst
Copy link

你是不是没改API_key,我刚才没改也是这样

@Kwaiyu Kwaiyu changed the title 脚本死循环 超出索引范围,脚本死循环 Jan 9, 2024
@Kwaiyu
Copy link
Author

Kwaiyu commented Jan 9, 2024

延长等待时间,或者加个重试当前索引项的函数可以解决了。closed

async function retryOperation(operation, delay, retries) {
  try {
    return await operation();
  } catch (error) {
    if (retries - 1 > 0) {
      console.log(`重试获取元素,剩余重试次数:${retries - 1}`);
      return new Promise((resolve) => setTimeout(resolve, delay))
          .then(() => retryOperation(operation, delay, retries - 1));
    } else {
      throw error;
    }
  }
}

@Kwaiyu Kwaiyu closed this as completed Jan 9, 2024
@noBaldAaa
Copy link
Owner

很秀[强]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants