修改时间
This commit is contained in:
@@ -26,7 +26,9 @@ public class CrawlerSchedule {
|
|||||||
// 每天凌晨2点执行爬取开奖结果
|
// 每天凌晨2点执行爬取开奖结果
|
||||||
//@Scheduled(cron = "0 0 2 * * ?")
|
//@Scheduled(cron = "0 0 2 * * ?")
|
||||||
// 每7秒执行一次爬取开奖结果
|
// 每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() {
|
public void executeLotteryDraw() {
|
||||||
System.out.println("开始爬取开奖结果...");
|
System.out.println("开始爬取开奖结果...");
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
@@ -53,8 +55,8 @@ public class CrawlerSchedule {
|
|||||||
// 创建爬虫实例,传入token
|
// 创建爬虫实例,传入token
|
||||||
LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token);
|
LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token);
|
||||||
|
|
||||||
String YesterdayDate = DateUtils.getYesterdayDate();// 4. 执行爬虫
|
String todayDate = DateUtils.getTodayDate();// 4. 执行爬虫
|
||||||
String url = firstByOrderByCreateTimeDesc.getLoginUrl()+"/member/dresult?lottery=SGFT&date="+YesterdayDate;
|
String url = firstByOrderByCreateTimeDesc.getLoginUrl()+"/member/dresult?lottery=SGFT&date="+todayDate;
|
||||||
|
|
||||||
Spider.create(crawler)
|
Spider.create(crawler)
|
||||||
.addUrl(url)
|
.addUrl(url)
|
||||||
|
|||||||
@@ -43,6 +43,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||||||
return yesterday.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
|
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) {
|
public static void main(String[] args) {
|
||||||
List<String> test = new ArrayList<>();
|
List<String> test = new ArrayList<>();
|
||||||
test.add("12312");
|
test.add("12312");
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ public class LotteryWebMagicCrawler implements PageProcessor {
|
|||||||
String directoryPath = "PyModel/data_test_dir"; // 项目根目录下的 output/json 文件夹
|
String directoryPath = "PyModel/data_test_dir"; // 项目根目录下的 output/json 文件夹
|
||||||
|
|
||||||
// 使用年月日作为文件名(格式:result_yyyyMMdd.json)
|
// 使用年月日作为文件名(格式:result_yyyyMMdd.json)
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
String dateStr = dateFormat.format(new Date());
|
String dateStr = dateFormat.format(new Date());
|
||||||
String fileName = "result_" + dateStr + ".json";
|
String fileName = "result_" + dateStr + ".json";
|
||||||
String filePath = directoryPath + "/" + fileName;
|
String filePath = directoryPath + "/" + fileName;
|
||||||
|
|||||||
Reference in New Issue
Block a user