修改时间

This commit is contained in:
xuelijun
2026-01-27 16:49:28 +08:00
parent 47fe421a9b
commit 639ea86e37
4 changed files with 16 additions and 4 deletions

View File

@@ -26,7 +26,9 @@ public class CrawlerSchedule {
// 每天凌晨2点执行爬取开奖结果
//@Scheduled(cron = "0 0 2 * * ?")
// 每7秒执行一次爬取开奖结果
//@Scheduled(cron = "*/9 * * * * ?")
@Scheduled(cron = "*/9 * * * * ?")
/*@Scheduled(cron = "0 6-59/5 7-23 * * ?")
@Scheduled(cron = "0 0-55/5 0-6 * * ?")*/
public void executeLotteryDraw() {
System.out.println("开始爬取开奖结果...");
int retryCount = 0;
@@ -53,8 +55,8 @@ public class CrawlerSchedule {
// 创建爬虫实例传入token
LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token);
String YesterdayDate = DateUtils.getYesterdayDate();// 4. 执行爬虫
String url = firstByOrderByCreateTimeDesc.getLoginUrl()+"/member/dresult?lottery=SGFT&date="+YesterdayDate;
String todayDate = DateUtils.getTodayDate();// 4. 执行爬虫
String url = firstByOrderByCreateTimeDesc.getLoginUrl()+"/member/dresult?lottery=SGFT&date="+todayDate;
Spider.create(crawler)
.addUrl(url)

View File

@@ -43,6 +43,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
return yesterday.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
}
/**
* 获取当天的日期,格式为 yyyy-MM-dd
*
* @return 当天日期的字符串例如2026-01-27
*/
public static String getTodayDate() {
LocalDate today = LocalDate.now();
return today.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
}
public static void main(String[] args) {
List<String> test = new ArrayList<>();
test.add("12312");

View File

@@ -251,7 +251,7 @@ public class LotteryWebMagicCrawler implements PageProcessor {
String directoryPath = "PyModel/data_test_dir"; // 项目根目录下的 output/json 文件夹
// 使用年月日作为文件名格式result_yyyyMMdd.json
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = dateFormat.format(new Date());
String fileName = "result_" + dateStr + ".json";
String filePath = directoryPath + "/" + fileName;