2021-12-08 23:46:06 +08:00
|
|
|
package com.yutou.qqbot.utlis;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
2021-12-09 12:39:41 +08:00
|
|
|
import org.openqa.selenium.*;
|
2021-12-08 23:46:06 +08:00
|
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
|
|
|
2021-12-09 12:39:41 +08:00
|
|
|
import java.io.File;
|
2021-12-12 17:39:50 +08:00
|
|
|
import java.util.*;
|
2021-12-08 23:46:06 +08:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
public class WebClient {
|
|
|
|
private static WebClient client;
|
|
|
|
|
|
|
|
|
|
|
|
public static WebClient getInstance() {
|
|
|
|
if (client == null) {
|
|
|
|
client = new WebClient();
|
|
|
|
}
|
|
|
|
return client;
|
|
|
|
}
|
2021-12-12 17:39:50 +08:00
|
|
|
public WebDriver getWebDriver(){
|
|
|
|
return new ChromeDriver(getOptions());
|
|
|
|
}
|
2021-12-08 23:46:06 +08:00
|
|
|
private WebClient() {
|
|
|
|
System.setProperty("webdriver.chrome.driver",
|
2021-12-09 12:39:41 +08:00
|
|
|
ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class));
|
|
|
|
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
2021-12-08 23:46:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-09 12:39:41 +08:00
|
|
|
|
|
|
|
|
2021-12-12 17:39:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
public static List<Cookie> loadCookie(JSONArray array){
|
|
|
|
List<Cookie> list=new ArrayList<>();
|
|
|
|
|
2021-12-09 12:39:41 +08:00
|
|
|
for (Object o : array) {
|
|
|
|
JSONObject json = (JSONObject) o;
|
2021-12-12 17:39:50 +08:00
|
|
|
boolean containsDate=json.containsKey("expirationDate");
|
|
|
|
long t=0;
|
|
|
|
if(containsDate) {
|
|
|
|
t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000;
|
|
|
|
}
|
|
|
|
|
2021-12-09 12:39:41 +08:00
|
|
|
Cookie cookie = new Cookie(json.getString("name"),
|
|
|
|
json.getString("value"),
|
|
|
|
json.getString("domain"),
|
|
|
|
json.getString("path"),
|
2021-12-12 17:39:50 +08:00
|
|
|
containsDate? new Date(t):null,
|
2021-12-09 12:39:41 +08:00
|
|
|
json.getBoolean("secure"),
|
|
|
|
json.getBoolean("httpOnly")
|
|
|
|
|
|
|
|
);
|
2021-12-12 17:39:50 +08:00
|
|
|
list.add(cookie);
|
2021-12-09 12:39:41 +08:00
|
|
|
}
|
2021-12-12 17:39:50 +08:00
|
|
|
return list;
|
2021-12-09 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
2021-12-12 17:39:50 +08:00
|
|
|
public static ChromeOptions getOptions() {
|
2021-12-08 23:46:06 +08:00
|
|
|
ChromeOptions options = new ChromeOptions();
|
2021-12-09 12:39:41 +08:00
|
|
|
options.addArguments("disable-infobars");
|
|
|
|
options.addArguments("blink-settings=imagesEnabled=false");
|
|
|
|
options.addArguments("--headless");
|
2021-12-09 02:50:53 +08:00
|
|
|
options.addArguments("--no-sandbox");
|
2021-12-08 23:46:06 +08:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
}
|
|
|
|
}
|