|
@@ -50,6 +50,8 @@ public class DataForSEOService {
|
|
|
private static final int MAX_TASKS_PER_SERP_REQUEST = 100;
|
|
|
private static final int SERP_STATUS_CODE_SUCCESS = 20000;
|
|
|
private static final int SERP_STATUS_CODE_TASK_CREATED = 20100;
|
|
|
+ private static final int SERP_STATUS_CODE_TASK_HANDED = 40601;
|
|
|
+ private static final int SERP_STATUS_CODE_TASK_IN_QUEUE = 40602;
|
|
|
|
|
|
// Google一页显示搜索结果数量
|
|
|
private static final int GOOGLE_SEARCH_PAGE_SIZE = 10;
|
|
@@ -223,11 +225,16 @@ public class DataForSEOService {
|
|
|
serpApi.googleOrganicTaskGetRegular(taskId).getTasks().get(0);
|
|
|
log.info("获取DataForSEO Serp任务,response = {}", JSONUtil.toJsonStr(serpTask));
|
|
|
if (serpTask.getStatusCode() != SERP_STATUS_CODE_SUCCESS) {
|
|
|
- log.warn(
|
|
|
+ log.info(
|
|
|
"DataForSEO Serp任务 {} 状态为 {} {}",
|
|
|
taskId,
|
|
|
serpTask.getStatusCode(),
|
|
|
serpTask.getStatusMessage());
|
|
|
+ // Serp task正在处理中...
|
|
|
+ if (Arrays.asList(SERP_STATUS_CODE_TASK_HANDED, SERP_STATUS_CODE_TASK_IN_QUEUE)
|
|
|
+ .contains(serpTask.getStatusCode())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
throw new ApiException(serpTask.getStatusMessage());
|
|
|
}
|
|
|
SerpGoogleOrganicTaskGetRegularResultInfo serpResult = serpTask.getResult().get(0);
|
|
@@ -246,8 +253,8 @@ public class DataForSEOService {
|
|
|
CommonUtil.getTopPrivateDomain(seoKeyword.getDomain()); // 顶级域名
|
|
|
OrganicSerpElementItem serpItem =
|
|
|
serpResult.getItems().stream()
|
|
|
- .map(item -> (OrganicSerpElementItem) item)
|
|
|
- .filter(item -> item.getType().equalsIgnoreCase("organic"))
|
|
|
+ .filter(OrganicSerpElementItem.class::isInstance)
|
|
|
+ .map(OrganicSerpElementItem.class::cast)
|
|
|
.filter(item -> item.getDomain().contains(topPrivateDomain)) // 根据域名匹配
|
|
|
.findAny()
|
|
|
.orElse(null);
|