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.
59 lines
2.3 KiB
59 lines
2.3 KiB
package com.crawler;
|
|
|
|
import com.crawler.chart.ChartGenerator;
|
|
import com.crawler.chart.ChartManager;
|
|
import com.crawler.chart.impl.GenreDistributionChartGenerator;
|
|
import com.crawler.chart.impl.RatingDistributionChartGenerator;
|
|
import com.crawler.chart.impl.YearDistributionChartGenerator;
|
|
import com.crawler.chart.impl.YearRatingChartGenerator;
|
|
import com.crawler.model.Movie;
|
|
import com.crawler.spider.DoubanSpider;
|
|
import com.crawler.utils.DataUtils;
|
|
import com.crawler.ui.MovieResultDisplay;
|
|
|
|
import java.util.List;
|
|
|
|
public class MovieMain {
|
|
public static void main(String[] args) {
|
|
try {
|
|
System.out.println("开始爬取豆瓣电影Top250数据...");
|
|
|
|
// 1. 启动爬虫
|
|
DoubanSpider spider = new DoubanSpider();
|
|
List<Movie> movieList = spider.crawlMovies();
|
|
|
|
// 2. 清洗数据
|
|
List<Movie> cleanedMovies = movieList.stream()
|
|
.map(DataUtils::cleanMovie)
|
|
.filter(movie -> movie != null)
|
|
.toList();
|
|
|
|
// 3. 保存数据到CSV文件
|
|
DataUtils.writeMovieToCSV(cleanedMovies, "douban_movies.csv");
|
|
System.out.println("数据已保存到 douban_movies.csv");
|
|
|
|
// 4. 展示结果
|
|
MovieResultDisplay.displayResults(cleanedMovies);
|
|
|
|
// 5. 使用多态生成图表
|
|
ChartManager chartManager = new ChartManager();
|
|
|
|
ChartGenerator ratingChart = new RatingDistributionChartGenerator();
|
|
ChartGenerator yearChart = new YearDistributionChartGenerator();
|
|
ChartGenerator genreChart = new GenreDistributionChartGenerator();
|
|
ChartGenerator yearRatingChart = new YearRatingChartGenerator();
|
|
|
|
chartManager.addChartGenerator(ratingChart);
|
|
chartManager.addChartGenerator(yearChart);
|
|
chartManager.addChartGenerator(genreChart);
|
|
chartManager.addChartGenerator(yearRatingChart);
|
|
|
|
chartManager.generateAllCharts(cleanedMovies);
|
|
|
|
System.out.println("\n爬虫任务完成!");
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|