新增百合会签到(未完成)
移动爬虫代码到对应模块里
This commit is contained in:
56
src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java
Normal file
56
src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.yutou.qqbot.models.WebSign;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.WebClient;
|
||||
import org.openqa.selenium.Cookie;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BaiHeHui extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
if("08:00".equals(time)){
|
||||
sign();
|
||||
}
|
||||
}
|
||||
|
||||
private void sign(){
|
||||
String cookie= ConfigTools.readFile(new File("baihehui.json"));
|
||||
if(StringUtils.isEmpty(cookie)){
|
||||
return;
|
||||
}
|
||||
WebDriver driver=WebClient.getInstance().getWebDriver();
|
||||
JSONArray array=JSONArray.parseArray(cookie);
|
||||
driver.get("https://bbs.yamibo.com/plugin.php?id=study_daily_attendance:daily_attendance&fhash=425430f7");
|
||||
for (Cookie _cookie : WebClient.loadCookie(array)) {
|
||||
driver.manage().addCookie(_cookie);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
driver.navigate().refresh();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BaiHeHui().sign();
|
||||
}
|
||||
}
|
||||
125
src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java
Normal file
125
src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java
Normal file
@@ -0,0 +1,125 @@
|
||||
package com.yutou.qqbot.models.WebSign;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.WebClient;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Cookie;
|
||||
import org.openqa.selenium.JavascriptExecutor;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.yutou.qqbot.utlis.WebClient.getOptions;
|
||||
|
||||
public class Tsdm extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[]{
|
||||
QQFromCommands.TSDM_PAY
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if(msg.startsWith(QQFromCommands.TSDM_PAY)){
|
||||
String url=msg.replace(QQFromCommands.TSDM_PAY,"").trim();
|
||||
if(StringUtils.isEmpty(url)){
|
||||
QQBotManager.getInstance().sendMessage(qq,"使用说明:!tsdm [url]");
|
||||
return;
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在获取,请稍等...");
|
||||
QQBotManager.getInstance().sendMessage(qq,tsdm(url));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
if("08:00".equals(time)){
|
||||
tsdmSign();
|
||||
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"已完成天使动漫的签到");
|
||||
}
|
||||
}
|
||||
|
||||
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 =WebClient.getInstance().getWebDriver();
|
||||
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 (Cookie cookie : WebClient.loadCookie(array)) {
|
||||
driver.manage().addCookie(cookie);
|
||||
}
|
||||
driver.navigate().refresh();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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 =WebClient.getInstance().getWebDriver();
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user