You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.6 KiB
46 lines
1.6 KiB
package com.yyt.moviecrawler.controller;
|
|
|
|
import com.yyt.moviecrawler.view.ConsoleView;
|
|
import com.yyt.moviecrawler.util.CrawlerContext;
|
|
import com.yyt.moviecrawler.model.Movie;
|
|
import com.yyt.moviecrawler.strategy.CrawlerStrategy;
|
|
import com.yyt.moviecrawler.strategy.DoubanStrategy;
|
|
import com.yyt.moviecrawler.strategy.XiaohongshuStrategy;
|
|
|
|
import java.util.List;
|
|
import java.util.Scanner;
|
|
|
|
public class CrawlerController {
|
|
private final ConsoleView view;
|
|
private final CrawlerContext context;
|
|
|
|
public CrawlerController(ConsoleView view, CrawlerContext context) {
|
|
this.view = view;
|
|
this.context = context;
|
|
}
|
|
|
|
public void doCrawl() {
|
|
try {
|
|
view.print("===== 开始爬取 =====");
|
|
|
|
// 1. 豆瓣电影
|
|
view.print("正在爬取豆瓣电影...");
|
|
context.setStrategy(new DoubanStrategy());
|
|
List<Movie> doubanMovies = context.executeStrategy(20);
|
|
view.print("豆瓣完成:" + doubanMovies.size() + "条");
|
|
|
|
// 2. 小红书电影(保留登录逻辑)
|
|
view.print("正在爬取小红书电影...");
|
|
System.out.println("⚠️ 小红书窗口已打开,请登录你的账号!登录完成后按回车继续");
|
|
Scanner scanner = new Scanner(System.in);
|
|
scanner.nextLine();
|
|
context.setStrategy(new XiaohongshuStrategy());
|
|
List<Movie> xhsMovies = context.executeStrategy(20);
|
|
view.print("小红书完成:" + xhsMovies.size() + "条");
|
|
|
|
view.print("===== 爬取结束 =====");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|