fix:调整了无头浏览器的流程:需要手动调用关闭浏览器方法
fix:调整了下载文件判断,如果下载结束后文件不存在则抛异常
This commit is contained in:
@@ -3,23 +3,37 @@ package com.yutou.qqbot.utlis;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.openqa.selenium.Cookie;
|
||||
import org.openqa.selenium.Proxy;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriverLogLevel;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class WebClient {
|
||||
private WebDriver driver;
|
||||
private static WebClient instance;
|
||||
|
||||
public static WebClient getInstance() {
|
||||
return new WebClient();
|
||||
if (instance == null || instance.driver == null) {
|
||||
instance = new WebClient();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public WebDriver getWebDriver() {
|
||||
return new ChromeDriver(getOptions());
|
||||
if (driver == null) {
|
||||
driver = new ChromeDriver(getOptions());
|
||||
}
|
||||
return driver;
|
||||
}
|
||||
|
||||
public void quit() {
|
||||
driver.quit();
|
||||
driver = null;
|
||||
}
|
||||
|
||||
private WebClient() {
|
||||
@@ -38,15 +52,15 @@ public class WebClient {
|
||||
boolean containsDate = json.containsKey("expirationDate");
|
||||
long t = 0;
|
||||
if (containsDate) {
|
||||
String _time=json.getString("expirationDate");
|
||||
if(_time.contains(".")){
|
||||
_time =_time.split("\\.")[0];
|
||||
String _time = json.getString("expirationDate");
|
||||
if (_time.contains(".")) {
|
||||
_time = _time.split("\\.")[0];
|
||||
}
|
||||
t = Long.parseLong(_time);
|
||||
}else{
|
||||
t=(System.currentTimeMillis())/1000;
|
||||
} else {
|
||||
t = (System.currentTimeMillis()) / 1000;
|
||||
}
|
||||
t*=1000;
|
||||
t *= 1000;
|
||||
|
||||
Cookie cookie = new Cookie(json.getString("name"),
|
||||
json.getString("value"),
|
||||
@@ -75,7 +89,11 @@ public class WebClient {
|
||||
String headless = RedisTools.get("chromedrive_headless");
|
||||
String proxy = RedisTools.get("chromedrive_proxy");
|
||||
if ("true".equals(proxy)) {
|
||||
options.addArguments("--proxy-server=http://127.0.0.1:7890");
|
||||
String url = "http://127.0.0.1:7890";
|
||||
Proxy _proxy = new Proxy();
|
||||
_proxy.setHttpProxy(url);
|
||||
_proxy.setSslProxy(url);
|
||||
options.setCapability(CapabilityType.PROXY, _proxy);
|
||||
}
|
||||
if ("true".equals(headless) || WebClient.headless) {
|
||||
options.addArguments("--headless");
|
||||
@@ -89,5 +107,8 @@ public class WebClient {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
WebDriver driver1 = getInstance().getWebDriver();
|
||||
|
||||
driver1.get("https://www.tsdm39.net/forum.php");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user