enable screenshot

This commit is contained in:
Niko 2026-05-22 10:29:41 +08:00
parent d635a35cc0
commit ef50ca0371

View File

@ -124,7 +124,9 @@ public class EtsScraper {
dateStrFileName = targetDate.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmm"));
}
Path savedFile = Path.of("downloads").resolve("三联单列表_" + dateStrFileName + ".xls");
Path downloadDir = Path.of("downloads").resolve(dateStrFileName);
Files.createDirectories(downloadDir);
Path savedFile = downloadDir.resolve("三联单列表_" + dateStrFileName + ".xls");
if (!isPolling && java.nio.file.Files.exists(savedFile) && java.nio.file.Files.size(savedFile) > 0) {
System.out.println("[+] File already exists: " + savedFile);
@ -158,6 +160,7 @@ public class EtsScraper {
try {
// Navigate to frame.html first to establish session/cookies
System.out.println("[*] Establishing session via " + FRAME_URL);
screenshot(page, "1_session_established", downloadDir);
page.navigate(FRAME_URL, new Page.NavigateOptions()
.setTimeout(30000)
.setWaitUntil(WaitUntilState.DOMCONTENTLOADED));
@ -178,6 +181,7 @@ public class EtsScraper {
// Close dialog again after page reload
closeNotificationDialog(page);
screenshot(page, "2_after_close_dialog", downloadDir);
// Recognize captcha and perform login
boolean loggedin = doLoginWithCaptcha(page);
@ -185,6 +189,7 @@ public class EtsScraper {
if (loggedin) {
System.out.println("[+] Login successful!");
sleep(2000);
screenshot(page, "4_after_login", downloadDir);
System.out.println("[+] Page title: " + page.title());
System.out.println("[+] Page URL: " + page.url());
@ -193,6 +198,7 @@ public class EtsScraper {
System.out.println("[*] Clicking 三联单 menu...");
page.locator("#module_2094F683-C542-4904-B33E-0D227C4DE199").first().click();
sleep(3000);
screenshot(page, "5_after_sanliandan_menu", downloadDir);
System.out.println("[+] 三联单 page title: " + page.title());
// 设置日期筛选
@ -218,6 +224,7 @@ public class EtsScraper {
System.out.println("[*] Setting end date to: " + dateStrFormatted);
page.locator("#Search_ThreeBillList_endWdate").first().fill(dateStrFormatted);
sleep(500);
screenshot(page, "6_after_date_set", downloadDir);
} else {
System.out.println("[!] End date element not found");
}
@ -229,6 +236,7 @@ public class EtsScraper {
page.locator("#Search_ThreeBillList_Button").first().click();
});
page.waitForTimeout(3 * 1000);
screenshot(page, "7_after_query", downloadDir);
} else {
System.out.println("[!] Query button not found");
}
@ -244,6 +252,7 @@ public class EtsScraper {
System.out.println("[*] Waiting for download to complete...");
dl.saveAs(savedFile);
screenshot(page, "8_after_export", downloadDir);
long totalBytes = savedFile.toFile().length();
System.out.println("[+] Download saved to: " + savedFile + " (" + totalBytes + " bytes)");
@ -335,6 +344,7 @@ public class EtsScraper {
Path captchaPath = SCREENSHOT_DIR.resolve("captcha.png");
java.nio.file.Files.write(captchaPath, body);
System.out.println("[+] Captcha saved to: " + captchaPath);
screenshot(page, "3_after_captcha", downloadDir);
System.out.println("[+] Captcha size: " + body.length + " bytes");
}
} catch (Exception e) {
@ -374,16 +384,15 @@ public class EtsScraper {
System.out.println("[*] Notification dialog closed");
}
private static void screenshot(Page page, String name) {
private static void screenshot(Page page, String name, Path dir) {
try {
String timestamp = LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmm"));
Path path = SCREENSHOT_DIR.resolve(name + "_" + timestamp + ".png");
Path path = dir.resolve(name + ".png");
page.screenshot(new Page.ScreenshotOptions().setPath(path));
System.out.println("[+] Screenshot saved: " + path);
} catch (Exception e) {
} catch (Exception e) {
System.err.println("[-] Screenshot failed: " + e.getMessage());
}
}
}
}
public static void sleep(long ms) {