修复了"学习通"平台中文档浏览任务的相关逻辑错误
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package work.slhaf.exception;
|
||||||
|
|
||||||
|
public class UnexpectedNumberTypeException extends RuntimeException {
|
||||||
|
public UnexpectedNumberTypeException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,7 @@ import org.openqa.selenium.interactions.Actions;
|
|||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import work.slhaf.config.Config;
|
import work.slhaf.config.Config;
|
||||||
import work.slhaf.exception.AiRequestException;
|
import work.slhaf.exception.*;
|
||||||
import work.slhaf.exception.AiResponseFormatException;
|
|
||||||
import work.slhaf.exception.OcrRequestException;
|
|
||||||
import work.slhaf.exception.TargetClassNotFoundException;
|
|
||||||
import work.slhaf.pojo.answer.Answer;
|
import work.slhaf.pojo.answer.Answer;
|
||||||
import work.slhaf.pojo.answer.MultiChoiceAnswer;
|
import work.slhaf.pojo.answer.MultiChoiceAnswer;
|
||||||
import work.slhaf.pojo.answer.SingleChoiceAnswer;
|
import work.slhaf.pojo.answer.SingleChoiceAnswer;
|
||||||
@@ -111,14 +108,38 @@ public class CxstudyTask {
|
|||||||
try {
|
try {
|
||||||
driver.switchTo().frame(i).switchTo().frame(2);
|
driver.switchTo().frame(i).switchTo().frame(2);
|
||||||
log.info("开始处理文档浏览...");
|
log.info("开始处理文档浏览...");
|
||||||
double lastHeight = (double) executor.executeScript("return document.body.scrollHeight;");
|
Object lastHeightObject = executor.executeScript("return document.body.scrollHeight;");
|
||||||
double currentHeight = 0;
|
String numberType = lastHeightObject.getClass().getSimpleName();
|
||||||
|
var lastHeight = switch (numberType){
|
||||||
|
case "Long" -> (Long) lastHeightObject;
|
||||||
|
case "Integer" -> (Integer) lastHeightObject;
|
||||||
|
case "Double" -> (Double) lastHeightObject;
|
||||||
|
default -> throw new UnexpectedNumberTypeException("未设置处理策略的高度值类型:" + numberType);
|
||||||
|
};
|
||||||
|
var currentHeight = switch (numberType){
|
||||||
|
case "Long" -> 0L;
|
||||||
|
case "Integer" -> 0;
|
||||||
|
case "Double" -> 0.0;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
int step = 2000;
|
int step = 2000;
|
||||||
while (currentHeight < lastHeight) {
|
while (currentHeight < lastHeight) {
|
||||||
executor.executeScript("window.scrollBy(0, arguments[0]);", step);
|
executor.executeScript("window.scrollBy(0, arguments[0]);", step);
|
||||||
Thread.sleep(600);
|
Thread.sleep(600);
|
||||||
currentHeight = (double) executor.executeScript("return document.body.scrollHeight;");
|
Object tempLastHeightObject = executor.executeScript("return document.body.scrollHeight;");
|
||||||
lastHeight = (double) executor.executeScript("return document.body.scrollHeight;");
|
lastHeight = switch (numberType) {
|
||||||
|
case "Long" -> (Long) tempLastHeightObject;
|
||||||
|
case "Integer" -> (Integer) tempLastHeightObject;
|
||||||
|
case "Double" -> (Double) tempLastHeightObject;
|
||||||
|
default -> throw new UnexpectedNumberTypeException("未设置处理策略的高度值类型: " + numberType);
|
||||||
|
};
|
||||||
|
Object tempCurrentHeightObject = executor.executeScript("return window.scrollY + window.innerHeight;");
|
||||||
|
currentHeight = switch (numberType) {
|
||||||
|
case "Long" -> (Long) tempCurrentHeightObject;
|
||||||
|
case "Integer" -> (Integer) tempCurrentHeightObject;
|
||||||
|
case "Double" -> (Double) tempCurrentHeightObject;
|
||||||
|
default -> throw new UnexpectedNumberTypeException("未设置处理策略的高度值类型: " + numberType);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
log.info("文档浏览任务完成!");
|
log.info("文档浏览任务完成!");
|
||||||
} catch (WebDriverException ignored) {
|
} catch (WebDriverException ignored) {
|
||||||
|
|||||||
Reference in New Issue
Block a user