Use createReadStream instead of saveAs for Excel download
Bypasses saveAs filesystem path which can produce 0-byte files in headless server environments. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
a393653497
commit
b86d0bf82f
@ -214,12 +214,21 @@ public class EtsScraper {
|
|||||||
page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })");
|
page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })");
|
||||||
});
|
});
|
||||||
System.out.println("[*] Waiting for download to complete...");
|
System.out.println("[*] Waiting for download to complete...");
|
||||||
dl.saveAs(savedFile);
|
long[] totalBytes = {0};
|
||||||
System.out.println("[+] Download saved to: " + savedFile);
|
try (java.io.InputStream stream = dl.createReadStream();
|
||||||
if (java.nio.file.Files.size(savedFile) == 0) {
|
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");
|
System.out.println("[-] Downloaded file is empty");
|
||||||
} else {
|
} 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
|
// Auto-import to ets-proxy
|
||||||
autoImportBill(savedFile, proxyHost, proxyUser, proxyPass);
|
autoImportBill(savedFile, proxyHost, proxyUser, proxyPass);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user