This commit is contained in:
ZiJIe 2025-06-25 11:53:18 +08:00
parent 2788e2db2a
commit 72b94a22b0
2 changed files with 17 additions and 7 deletions

View File

@ -274,8 +274,7 @@ public class BanmaOrderController extends BaseController {
Thread thread = new Thread(() -> {
try {
int size = 20;
// 若已超时或已完成则不处理
int size = 20;
if (deferredResult.isSetOrExpired()) return;
R<List<Map<String, Object>>> pageResult = getOrders(page, size);

View File

@ -99,7 +99,7 @@ public class WebMagicController extends BaseController implements PageProcessor
private void loadProxyConfig() {
try {
//File configFile = ResourceUtils.getFile("classpath:test_proxy.yml");
File configFile = new File("/www/java_mall/erp/config/test_proxy.yml");
File configFile = new File("/www/java_mall/erp/config/test_proxy.yml");
if (configFile.exists()) {
Yaml yaml = new Yaml();
try (InputStream inputStream = new FileInputStream(configFile)) {
@ -176,10 +176,8 @@ public class WebMagicController extends BaseController implements PageProcessor
if (priceSymbol != null && !priceSymbol.isEmpty() && priceWhole != null && !priceWhole.isEmpty()) {
resultMap.put("price", priceSymbol + priceWhole);
}
resultMap.put("seller", html.xpath("//a[@id='sellerProfileTriggerId']/text()").toString());
resultMap.put("asin", html.xpath("//input[@id='ASIN']/@value").toString());
String price = (String) resultMap.get("price");
String seller = (String) resultMap.get("seller");
Object retriesObj = page.getRequest().getExtra("retries");
@ -268,12 +266,25 @@ public class WebMagicController extends BaseController implements PageProcessor
.setDownloader(getProxyDownloader())
.thread(1);
spider.run();
String price = (String) resultMap.get("price");
String resultAsin = (String) resultMap.get("asin");
if ((resultAsin == null || resultAsin.isEmpty() || price == null || price.isEmpty())) {
Thread.sleep(1000 + random.nextInt(2000));
logger.info("ASIN{} 的价格或ASIN为空进行一次重试", asin);
resultMap = new HashMap<>();
resultMap.put("asin", asin);
spider = Spider.create(this)
.addUrl(url)
.setDownloader(getProxyDownloader())
.thread(1);
spider.run();
}
} finally {
clearSystemProxy();
}
resultList.add(new HashMap<>(resultMap));
}
deferredResult.setResult(ResponseEntity.ok(R.ok(resultList)));
} catch (Exception e) {