diff --git a/src/main/java/com/ets/scraper/EtsScraper.java b/src/main/java/com/ets/scraper/EtsScraper.java index a8f4bca..47c7902 100644 --- a/src/main/java/com/ets/scraper/EtsScraper.java +++ b/src/main/java/com/ets/scraper/EtsScraper.java @@ -214,12 +214,21 @@ public class EtsScraper { page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })"); }); System.out.println("[*] Waiting for download to complete..."); - dl.saveAs(savedFile); - System.out.println("[+] Download saved to: " + savedFile); - if (java.nio.file.Files.size(savedFile) == 0) { + long[] totalBytes = {0}; + try (java.io.InputStream stream = dl.createReadStream(); + java.io.OutputStream out = Files.newOutputStream(savedFile)) { + byte[] buf = new byte[8192]; + int n; + while ((n = stream.read(buf)) > 0) { + out.write(buf, 0, n); + totalBytes[0] += n; + } + } + System.out.println("[+] Download saved to: " + savedFile + " (" + totalBytes[0] + " bytes)"); + if (totalBytes[0] == 0) { System.out.println("[-] Downloaded file is empty"); } else { - System.out.println("[+] Download size: " + java.nio.file.Files.size(savedFile) + " bytes"); + System.out.println("[+] Download size: " + totalBytes[0] + " bytes"); // Auto-import to ets-proxy autoImportBill(savedFile, proxyHost, proxyUser, proxyPass); }