use of com.ruiyun.jvppeteer.options.LaunchOptions in project epic4j by huisunan.
the class MainStart method getBrowser.
@Override
@SneakyThrows
public Browser getBrowser(String dataPath) {
log.debug("driver data path :{}", dataPath);
if (epicConfig.getNoSandbox()) {
epicConfig.getDriverArgs().add("--no-sandbox");
}
// 自动下载,第一次下载后不会再下载
if (Arrays.stream(Constant.EXECUTABLE_ENV).noneMatch(env -> {
String chromeExecutable = System.getenv(env);
return StrUtil.isNotBlank(chromeExecutable) && FileUtil.assertExecutable(chromeExecutable);
})) {
BrowserFetcher.downloadIfNotExist(epicConfig.getBrowserVersion());
}
LaunchOptions options = new LaunchOptionsBuilder().withArgs(epicConfig.getDriverArgs()).withHeadless(epicConfig.getHeadLess()).withUserDataDir(dataPath).withIgnoreDefaultArgs(Collections.singletonList("--enable-automation")).build();
return Puppeteer.launch(options);
}
use of com.ruiyun.jvppeteer.options.LaunchOptions in project epic4j by huisunan.
the class CrawTest method test.
@Test
@SneakyThrows
public void test() {
BrowserFetcher.downloadIfNotExist("938248");
String dataPath = new FileUrlResource("./data/chrome/tests").getFile().getAbsolutePath();
LaunchOptions options = new LaunchOptionsBuilder().withArgs(Arrays.asList("--blink-settings=imagesEnabled=false", "--no-first-run", "--disable-gpu", "--no-default-browser-check", "--no-sandbox")).withHeadless(false).withUserDataDir(dataPath).withExecutablePath("").withIgnoreDefaultArgs(Collections.singletonList("--enable-automation")).build();
Browser browser = Puppeteer.launch(options);
Page page = browser.pages().get(0);
// PageUtil.crawSet(page);
// page.goTo("http://localhost:9999/");
page.goTo("http://www.baidu.com/");
TimeUnit.SECONDS.sleep(10);
FileUrlResource errorDir = new FileUrlResource("data/test");
File file = errorDir.getFile();
log.debug("mkdir {}", file.mkdirs());
ScreenshotOptions screenshotOptions = new ScreenshotOptions();
screenshotOptions.setQuality(100);
screenshotOptions.setPath(file.getAbsolutePath() + File.separator + "report.jpg");
screenshotOptions.setType("jpeg");
page.screenshot(screenshotOptions);
FileUtil.writeUtf8String(page.content(), new File(file.getAbsolutePath() + File.separator + "report.html"));
log.info("success");
}
Aggregations