Skip download and import directly if file for the date already exists
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
c7a4683340
commit
9174a4cc40
@ -81,6 +81,16 @@ public class EtsScraper {
|
||||
|
||||
String dateStrFileName = targetDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
|
||||
Path downloadPath = Path.of("downloads").toAbsolutePath().normalize();
|
||||
Path savedFile = downloadPath.resolve("三联单列表_" + dateStrFileName + ".xls");
|
||||
|
||||
if (java.nio.file.Files.exists(savedFile) && java.nio.file.Files.size(savedFile) > 0) {
|
||||
System.out.println("[+] File already exists: " + savedFile);
|
||||
System.out.println("[+] File size: " + java.nio.file.Files.size(savedFile) + " bytes");
|
||||
autoImportBill(savedFile, proxyHost, proxyUser, proxyPass);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
createDirectories(SCREENSHOT_DIR);
|
||||
} catch (Exception e) {
|
||||
@ -195,8 +205,6 @@ public class EtsScraper {
|
||||
if (page.locator("#Export_ThreeBillList_Button").count() > 0) {
|
||||
System.out.println("[*] Clicking export button...");
|
||||
// 设置下载目录
|
||||
Path downloadPath = Path.of("downloads").toAbsolutePath().normalize();
|
||||
java.nio.file.Files.createDirectories(downloadPath);
|
||||
// 点击主导出按钮打开对话框,再用 JS click 触发对话框内导出按钮
|
||||
Download dl = page.waitForDownload(
|
||||
new Page.WaitForDownloadOptions().setTimeout(300000),
|
||||
@ -207,7 +215,6 @@ public class EtsScraper {
|
||||
page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })");
|
||||
});
|
||||
System.out.println("[*] Waiting for download to complete...");
|
||||
Path savedFile = downloadPath.resolve("三联单列表_" + dateStrFileName + ".xls");
|
||||
dl.saveAs(savedFile);
|
||||
System.out.println("[+] Download saved to: " + savedFile);
|
||||
if (java.nio.file.Files.size(savedFile) == 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user