From af9be86762f7dbecebda22982ac82e2a3d5b1ed1 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 5 May 2022 09:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4WebClient=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/QQBotApplication.java | 2 +- .../java/com/yutou/qqbot/utlis/WebClient.java | 32 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index cadab2d..e16a1ac 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.2.25"; + public static final String version="QQBot v.1.2.26"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/utlis/WebClient.java b/src/main/java/com/yutou/qqbot/utlis/WebClient.java index f22618f..3b783cd 100644 --- a/src/main/java/com/yutou/qqbot/utlis/WebClient.java +++ b/src/main/java/com/yutou/qqbot/utlis/WebClient.java @@ -13,14 +13,9 @@ import java.util.Date; import java.util.List; public class WebClient { - private static WebClient client; - public static WebClient getInstance() { - if (client == null) { - client = new WebClient(); - } - return client; + return new WebClient(); } public WebDriver getWebDriver() { @@ -30,7 +25,7 @@ public class WebClient { private WebClient() { System.setProperty("webdriver.chrome.driver", ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class)); - // System.setProperty("webdriver.chrome.whitelistedIps", ""); + // System.setProperty("webdriver.chrome.whitelistedIps", ""); // java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); } @@ -59,24 +54,27 @@ public class WebClient { } return list; } - static boolean headless=false; - public static void setHeadless(boolean headless){ - WebClient.headless=headless; + + static boolean headless = false; + + public void setHeadless(boolean headless) { + WebClient.headless = headless; } - public static ChromeOptions getOptions() { + + public ChromeOptions getOptions() { ChromeOptions options = new ChromeOptions(); - // options.addArguments("--disable-gpu"); - // options.addArguments("blink-settings=imagesEnabled=false"); + // options.addArguments("--disable-gpu"); + // options.addArguments("blink-settings=imagesEnabled=false"); String headless = RedisTools.get("chromedrive_headless"); - String proxy=RedisTools.get("chromedrive_proxy"); - if("true".equals(proxy)) { + String proxy = RedisTools.get("chromedrive_proxy"); + if ("true".equals(proxy)) { options.addArguments("--proxy-server=http://127.0.0.1:7890"); } - if("true".equals(headless)||WebClient.headless) { + if ("true".equals(headless) || WebClient.headless) { options.addArguments("--headless"); } options.addArguments("--no-sandbox"); - // options.addArguments("--incognito"); + // options.addArguments("--incognito"); options.addArguments("--disable-plugins"); options.addArguments("--lang=zh-CN");