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;
|
|
|
|
import java.util.Date;
|
2021-12-08 23:46:06 +08:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
public class WebClient {
|
|
|
|
private static WebClient client;
|
|
|
|
|
|
|
|
|
|
|
|
public static WebClient getInstance() {
|
|
|
|
if (client == null) {
|
|
|
|
client = new WebClient();
|
|
|
|
}
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
2021-12-09 12:39:41 +08:00
|
|
|
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
2021-12-08 23:46:06 +08:00
|
|
|
prices,
|
|
|
|
pattern == null ? "" : "&pattern=" + pattern
|
|
|
|
);
|
|
|
|
System.out.println("url = " + url);
|
|
|
|
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
|
|
|
WebDriver webDriver = new ChromeDriver(getOptions());
|
|
|
|
|
|
|
|
webDriver.get(url);
|
|
|
|
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
|
|
|
Thread.sleep(500);
|
|
|
|
WebElement element = webDriver.findElement(By.id("output"));
|
|
|
|
List<WebElement> list = element.findElements(By.tagName("tr"));
|
|
|
|
JSONObject pr = new JSONObject();
|
|
|
|
JSONArray array = new JSONArray();
|
2021-12-09 12:39:41 +08:00
|
|
|
if (list.size() == 0) {
|
2021-12-09 02:50:53 +08:00
|
|
|
return null;
|
|
|
|
}
|
2021-12-08 23:46:06 +08:00
|
|
|
|
|
|
|
for (WebElement webElement : list) {
|
|
|
|
String[] tmp;
|
|
|
|
try {
|
|
|
|
tmp = webElement.getText().replace(" ~ ", "~").split(" ");
|
|
|
|
} catch (Exception e) {
|
|
|
|
//e.printStackTrace();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ("所有趋势".equals(tmp[0])) {
|
|
|
|
map.put(TurnipProphet.TurnipData.MONDAY_UP, tmp[3]);
|
|
|
|
map.put(TurnipProphet.TurnipData.MONDAY_DOWN, tmp[4]);
|
|
|
|
map.put(TurnipProphet.TurnipData.TUESDAY_UP, tmp[5]);
|
|
|
|
map.put(TurnipProphet.TurnipData.TUESDAY_DOWN, tmp[6]);
|
|
|
|
map.put(TurnipProphet.TurnipData.WEDNESDAY_UP, tmp[7]);
|
|
|
|
map.put(TurnipProphet.TurnipData.WEDNESDAY_DOWN, tmp[8]);
|
|
|
|
map.put(TurnipProphet.TurnipData.THURSDAY_UP, tmp[9]);
|
|
|
|
map.put(TurnipProphet.TurnipData.THURSDAY_DOWN, tmp[10]);
|
|
|
|
map.put(TurnipProphet.TurnipData.FRIDAY_UP, tmp[11]);
|
|
|
|
map.put(TurnipProphet.TurnipData.FRIDAY_DOWN, tmp[12]);
|
|
|
|
map.put(TurnipProphet.TurnipData.SATURDAY_UP, tmp[13]);
|
|
|
|
map.put(TurnipProphet.TurnipData.SATURDAY_DOWN, tmp[14]);
|
|
|
|
|
|
|
|
map.put(TurnipProphet.TurnipData.MIX, tmp[15]);
|
|
|
|
map.put(TurnipProphet.TurnipData.MAX, tmp[16]);
|
|
|
|
} else {
|
|
|
|
if (!array.toJSONString().contains(tmp[0])) {
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
json.put(TurnipProphet.TurnipData.MODEL, tmp[0]);
|
|
|
|
json.put(TurnipProphet.TurnipData.PR, tmp[1]);
|
|
|
|
array.add(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String key : map.keySet()) {
|
2021-12-09 12:39:41 +08:00
|
|
|
System.err.println("记录最高日:" + map.get(key) + " > " + key);
|
2021-12-08 23:46:06 +08:00
|
|
|
if (!key.equals(TurnipProphet.TurnipData.MAX) &&
|
|
|
|
map.get(key).contains(map.get(TurnipProphet.TurnipData.MAX))) {
|
|
|
|
map.put(TurnipProphet.TurnipData.DAY, key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pr.put(TurnipProphet.TurnipData.MODEL, array);
|
|
|
|
map.put(TurnipProphet.TurnipData.MODEL, pr.toJSONString());
|
|
|
|
webDriver.close();
|
2021-12-09 12:39:41 +08:00
|
|
|
webDriver.quit();
|
2021-12-08 23:46:06 +08:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2021-12-09 12:39:41 +08:00
|
|
|
public String tsdm(String url) {
|
|
|
|
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json")));
|
|
|
|
if (array == null) {
|
|
|
|
System.err.println("array is null");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
WebDriver driver = new ChromeDriver(getOptions());
|
|
|
|
driver.get(url);
|
|
|
|
getTsdm(array, driver);
|
|
|
|
try {
|
|
|
|
((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('y viewpay')[0].click()");
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
driver.findElement(By.id("payform")).submit();
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
|
|
|
}
|
|
|
|
String body = driver.findElement(By.name("tsdmlz")).getText();
|
|
|
|
driver.close();
|
|
|
|
driver.quit();
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
public void tsdmSign(){
|
|
|
|
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json")));
|
|
|
|
if (array == null) {
|
|
|
|
System.err.println("array is null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WebDriver driver = new ChromeDriver(getOptions());
|
|
|
|
driver.get("https://www.tsdm39.net/forum.php");
|
|
|
|
getTsdm(array, driver);
|
|
|
|
try {
|
|
|
|
((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')");
|
|
|
|
}catch (Exception ignored){
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
driver.findElement(By.id("wl")).click();
|
|
|
|
driver.findElement(By.xpath("//input[@value='3']")).click();
|
|
|
|
driver.findElement(By.id("qiandao")).submit();
|
|
|
|
driver.close();
|
|
|
|
driver.quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getTsdm(JSONArray array, WebDriver driver) {
|
|
|
|
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
for (Object o : array) {
|
|
|
|
JSONObject json = (JSONObject) o;
|
|
|
|
long t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000;
|
|
|
|
Cookie cookie = new Cookie(json.getString("name"),
|
|
|
|
json.getString("value"),
|
|
|
|
json.getString("domain"),
|
|
|
|
json.getString("path"),
|
|
|
|
new Date(t),
|
|
|
|
json.getBoolean("secure"),
|
|
|
|
json.getBoolean("httpOnly")
|
|
|
|
|
|
|
|
);
|
|
|
|
driver.manage().addCookie(cookie);
|
|
|
|
}
|
|
|
|
driver.navigate().refresh();
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 23:46:06 +08:00
|
|
|
private ChromeOptions getOptions() {
|
|
|
|
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) {
|
2021-12-09 12:39:41 +08:00
|
|
|
WebClient.getInstance().tsdmSign();
|
2021-12-08 23:46:06 +08:00
|
|
|
}
|
|
|
|
}
|