|
@@ -87,20 +87,16 @@ public class ScreenshotUtil {
|
|
|
private FileUtils fileUtils;
|
|
|
|
|
|
public void screenshot(long jobId, List<ImageContent> imageContents, Integer imageWidth) {
|
|
|
- System.out.println(">>>>>>>>>>>>>>imageContents>>>>>>>>>>>>>>>>"+imageContents.size());
|
|
|
scheduleLogger.info("Start screenshot for job({})", jobId);
|
|
|
try {
|
|
|
int contentsSize = imageContents.size();
|
|
|
List<Future> futures = new ArrayList<>(contentsSize);
|
|
|
final AtomicInteger index = new AtomicInteger(1);
|
|
|
imageContents.forEach(content -> futures.add(executorService.submit(() -> {
|
|
|
- System.out.println(">>>>>>>>>>>>>>content>>>>>>>>>>>>>>>>"+content.getUrl());
|
|
|
scheduleLogger.info("Cronjob({}) thread({}) for screenshot start, type:{}, id:{}, total:{}", jobId, index.get(), content.getDesc(), content.getCId(), contentsSize);
|
|
|
try {
|
|
|
- System.out.println(">>>>>>>>>>>>>>生成图片>>>>>>>>>>>>>>>>");
|
|
|
File image = doScreenshot(jobId, content.getUrl(), imageWidth);
|
|
|
content.setContent(image);
|
|
|
- System.out.println(">>>>>>>>>>>>>>设置文件>>>>>>>>>>>>>>>>");
|
|
|
} catch (Exception e) {
|
|
|
scheduleLogger.error("Cronjob({}) thread( {}) screenshot error", jobId, index.get());
|
|
|
scheduleLogger.error(e.getMessage(), e);
|
|
@@ -128,9 +124,7 @@ public class ScreenshotUtil {
|
|
|
}
|
|
|
|
|
|
private File doScreenshot(long jobId, String url, Integer imageWidth) throws Exception {
|
|
|
- System.out.println(">>>>>>>jobId>>>>>>>>"+ jobId);
|
|
|
WebDriver driver = generateWebDriver(jobId, imageWidth);
|
|
|
- System.out.println(">>>>>>>url>>>>>>>>"+ url);
|
|
|
driver.get(url);
|
|
|
scheduleLogger.info("Cronjob({}) do screenshot url={}, timeout={} start", jobId, url, timeOutSecond);
|
|
|
try {
|
|
@@ -225,14 +219,15 @@ public class ScreenshotUtil {
|
|
|
}
|
|
|
|
|
|
if(isLinux()){
|
|
|
- CHROME_DRIVER_PATH += "/linux";
|
|
|
+ CHROME_DRIVER_PATH += "/linux/chromedriver";
|
|
|
}
|
|
|
if(isWindows()){
|
|
|
CHROME_DRIVER_PATH += "/window";
|
|
|
}
|
|
|
- System.out.println("CHROME_DRIVER_PATH >>>> " + CHROME_DRIVER_PATH);
|
|
|
+
|
|
|
|
|
|
File file = new File(CHROME_DRIVER_PATH);
|
|
|
+
|
|
|
if (!file.canExecute()) {
|
|
|
if (!file.setExecutable(true)) {
|
|
|
throw new ExecutionException(new Exception(CHROME_DRIVER_PATH + " is not executable!"));
|
|
@@ -256,10 +251,32 @@ public class ScreenshotUtil {
|
|
|
return new ChromeDriver(options);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws ExecutionException {
|
|
|
|
|
|
String OS = System.getProperty("os.name").toLowerCase();
|
|
|
+ File file = new File("D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver");
|
|
|
+
|
|
|
+ if (!file.canExecute()) {
|
|
|
+ if (!file.setExecutable(true)) {
|
|
|
+ throw new ExecutionException(new Exception("D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver" + " is not executable!"));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver");
|
|
|
+ ChromeOptions options = new ChromeOptions();
|
|
|
+
|
|
|
+ options.addArguments("headless");
|
|
|
+ options.addArguments("no-sandbox");
|
|
|
+ options.addArguments("disable-gpu");
|
|
|
+ options.addArguments("disable-features=NetworkService");
|
|
|
+ options.addArguments("ignore-certificate-errors");
|
|
|
+ options.addArguments("silent-launch");
|
|
|
+ options.addArguments("disable-application-cache");
|
|
|
+ options.addArguments("disable-web-security");
|
|
|
+ options.addArguments("no-proxy-server");
|
|
|
+ options.addArguments("disable-dev-shm-usage");
|
|
|
+ WebDriver driver = new ChromeDriver(options);
|
|
|
+ System.out.println(driver.getTitle());
|
|
|
System.out.println(OS);
|
|
|
|
|
|
}
|