From 3ce85b439c4ad00d18a9a4b9a69b290430c46088 Mon Sep 17 00:00:00 2001 From: peisishuang <1767255628@qq.com> Date: Fri, 1 May 2026 19:33:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'=E6=96=B0=E9=97=BB=E7=BD=91=E7=88=AC=E8=99=AB'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 新闻网爬虫/HelpCommand.java | 30 ++++++++++++++++++++++++++ 新闻网爬虫/ListCommand.java | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 新闻网爬虫/HelpCommand.java create mode 100644 新闻网爬虫/ListCommand.java diff --git a/新闻网爬虫/HelpCommand.java b/新闻网爬虫/HelpCommand.java new file mode 100644 index 0000000..3ea161b --- /dev/null +++ b/新闻网爬虫/HelpCommand.java @@ -0,0 +1,30 @@ +package com.cctv.news.command; + +import com.cctv.news.view.OutputView; + +public class HelpCommand implements Command { + private final OutputView view; + + public HelpCommand(OutputView view) { + this.view = view; + } + + @Override + public String getName() { + return "help"; + } + + @Override + public String getHelp() { + return "help - 显示帮助信息"; + } + + @Override + public void execute(String[] args) { + view.showMessage("可用命令:"); + view.showMessage(" help - 显示帮助信息"); + view.showMessage(" list - 显示已抓取的文章列表"); + view.showMessage(" crawl - 爬取央视新闻"); + view.showMessage(" exit - 退出程序"); + } +} diff --git a/新闻网爬虫/ListCommand.java b/新闻网爬虫/ListCommand.java new file mode 100644 index 0000000..07a01cf --- /dev/null +++ b/新闻网爬虫/ListCommand.java @@ -0,0 +1,36 @@ +package com.cctv.news.command; + +import com.cctv.news.view.OutputView; +import java.util.List; + +public class ListCommand implements Command { + private final OutputView view; + private final List articles; + + public ListCommand(OutputView view, List articles) { + this.view = view; + this.articles = articles; + } + + @Override + public String getName() { + return "list"; + } + + @Override + public String getHelp() { + return "list - 显示已抓取的文章列表"; + } + + @Override + public void execute(String[] args) { + if (articles.isEmpty()) { + view.showMessage("目前没有已抓取的文章,请先使用 crawl 命令。"); + } else { + view.showMessage("已抓取的文章列表:"); + for (int i = 0; i < articles.size(); i++) { + view.showArticles((i + 1) + ". " + articles.get(i)); + } + } + } +}