更新依赖

百合会签到改为模拟登陆行为
WebClient导入Cookie修复时间异常问题
This commit is contained in:
Yutousama 2022-06-27 10:02:47 +08:00
parent 8ddfc339dd
commit 299bc17758
5 changed files with 40 additions and 17 deletions

View File

@ -81,24 +81,24 @@
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<version>4.1.4</version> <version>4.2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId> <artifactId>selenium-chrome-driver</artifactId>
<version>4.1.4</version> <version>4.2.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api --> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId> <artifactId>selenium-api</artifactId>
<version>4.1.4</version> <version>4.2.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver --> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId> <artifactId>selenium-remote-driver</artifactId>
<version>4.1.4</version> <version>4.2.1</version>
</dependency> </dependency>

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class QQBotApplication { public class QQBotApplication {
public static final String version="QQBot v.1.2.28"; public static final String version="QQBot v.1.2.29";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("version = " + version); System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args); SpringApplication.run(QQBotApplication.class, args);

View File

@ -6,7 +6,6 @@ import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
@ -57,16 +56,21 @@ public class BaiHeHui extends Model {
JSONArray array = JSON.parseArray(cookie); JSONArray array = JSON.parseArray(cookie);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get("https://bbs.yamibo.com/forum.php"); driver.get("https://bbs.yamibo.com/forum.php");
driver.manage().deleteAllCookies(); login(driver);
// driver.manage().deleteAllCookies();
/* Thread.sleep(1000);
for (Cookie _cookie : WebClient.loadCookie(array)) { for (Cookie _cookie : WebClient.loadCookie(array)) {
System.err.println(_cookie);
driver.manage().addCookie(_cookie); driver.manage().addCookie(_cookie);
} Thread.sleep(100);
}*/
try { try {
Thread.sleep(500); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
driver.navigate().refresh(); driver.navigate().refresh();
driver.get("https://bbs.yamibo.com/forum.php");
for (WebElement element : driver.findElements(By.xpath("//a"))) { for (WebElement element : driver.findElements(By.xpath("//a"))) {
if ("打卡签到".equals(element.getText())) { if ("打卡签到".equals(element.getText())) {
element.click(); element.click();
@ -83,7 +87,19 @@ public class BaiHeHui extends Model {
} }
} }
public static void main(String[] args) { private void login(WebDriver driver) {
driver.get("https://bbs.yamibo.com/member.php?mod=logging&action=login");
driver.findElement(By.name("username")).sendKeys("z583819556");
driver.findElement(By.name("password")).sendKeys("u8fi4Qfr.5D2wZ5");
driver.findElement(By.name("loginsubmit")).submit();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
new BaiHeHui().sign();
} }
} }

View File

@ -154,6 +154,6 @@ public class Tsdm extends Model {
} }
public static void main(String[] args) { public static void main(String[] args) {
new Tsdm().tsdmSign();
} }
} }

View File

@ -38,14 +38,21 @@ public class WebClient {
boolean containsDate = json.containsKey("expirationDate"); boolean containsDate = json.containsKey("expirationDate");
long t = 0; long t = 0;
if (containsDate) { if (containsDate) {
t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000; String _time=json.getString("expirationDate");
if(_time.contains(".")){
_time =_time.split("\\.")[0];
} }
t = Long.parseLong(_time);
}else{
t=(System.currentTimeMillis())/1000;
}
t*=1000;
Cookie cookie = new Cookie(json.getString("name"), Cookie cookie = new Cookie(json.getString("name"),
json.getString("value"), json.getString("value"),
json.getString("domain"), json.getString("domain"),
json.getString("path"), json.getString("path"),
containsDate ? new Date(t) : new Date(), new Date(t),
json.getBooleanValue("secure"), json.getBooleanValue("secure"),
json.getBooleanValue("httpOnly") json.getBooleanValue("httpOnly")