perf: 爬虫分类规则优化

This commit is contained in:
xiongxiaoyang 2025-03-14 19:03:30 +08:00
parent 74d7ea7000
commit 6d0ab33757

View File

@ -255,12 +255,21 @@ public class CrawlServiceImpl implements CrawlService {
while (page <= totalPage) { while (page <= totalPage) {
try { try {
String catIdRule = ruleBean.getCatIdRule().get("catId" + catId);
if (StringUtils.isNotBlank(ruleBean.getCatIdRule().get("catId" + catId))) { if (StringUtils.isNotBlank(catIdRule)) {
//拼接分类URL String catBookListUrl = "";
String catBookListUrl = ruleBean.getBookListUrl() if (StringUtils.isNotBlank(ruleBean.getBookListUrl())) {
.replace("{catId}", ruleBean.getCatIdRule().get("catId" + catId)) // 兼容老规则
// 拼接分类URL
catBookListUrl = ruleBean.getBookListUrl()
.replace("{catId}", catIdRule)
.replace("{page}", page + ""); .replace("{page}", page + "");
} else {
// 新规则
// 拼接分类URL
catBookListUrl = catIdRule.replace("{page}", page + "");
}
log.info("catBookListUrl{}", catBookListUrl);
String bookListHtml = crawlHttpClient.get(catBookListUrl); String bookListHtml = crawlHttpClient.get(catBookListUrl);
if (bookListHtml != null) { if (bookListHtml != null) {