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.
70 lines
2.7 KiB
70 lines
2.7 KiB
package view;
|
|
|
|
import model.Article;
|
|
import java.util.Scanner;
|
|
|
|
public class ConsoleView {
|
|
private Scanner scanner;
|
|
|
|
public ConsoleView() {
|
|
scanner = new Scanner(System.in);
|
|
}
|
|
|
|
public void showWelcome() {
|
|
System.out.println("\n╔══════════════════════════════════════╗");
|
|
System.out.println("║ 多网站爬虫系统 - CLI版本 ║");
|
|
System.out.println("╚══════════════════════════════════════╝\n");
|
|
}
|
|
|
|
public void showHelp() {
|
|
System.out.println("\n========== 帮助信息 ==========");
|
|
System.out.println("可用命令:");
|
|
System.out.println(" 1 或 jjwxc - 爬取晋江文学城");
|
|
System.out.println(" 2 或 baidu - 爬取百度");
|
|
System.out.println(" 3 或 httpbin - 爬取HttpBin");
|
|
System.out.println(" 4 或 bing - 爬取必应搜索");
|
|
System.out.println(" all - 爬取所有网站");
|
|
System.out.println(" list - 显示已爬取数据");
|
|
System.out.println(" save - 保存数据到文件");
|
|
System.out.println(" help - 显示帮助信息");
|
|
System.out.println(" exit - 退出程序");
|
|
System.out.println("==============================\n");
|
|
}
|
|
|
|
public void showMessage(String message) {
|
|
System.out.println(message);
|
|
}
|
|
|
|
public void showError(String error) {
|
|
System.out.println("[错误] " + error);
|
|
}
|
|
|
|
public void showArticle(Article article) {
|
|
System.out.println("\n---------- 爬取结果 ----------");
|
|
System.out.println("来源: " + article.getSource());
|
|
System.out.println("标题: " + article.getTitle());
|
|
System.out.println("链接: " + article.getUrl());
|
|
String content = article.getContent();
|
|
if (content != null && content.length() > 200) {
|
|
content = content.substring(0, 200) + "...";
|
|
}
|
|
System.out.println("内容: " + content);
|
|
System.out.println("------------------------------\n");
|
|
}
|
|
|
|
public String getInput() {
|
|
System.out.print("请输入命令 > ");
|
|
return scanner.nextLine().trim().toLowerCase();
|
|
}
|
|
|
|
public void showGoodbye() {
|
|
System.out.println("\n感谢使用,再见!");
|
|
}
|
|
|
|
public void showStrategies(String[] names) {
|
|
System.out.println("\n可用网站:");
|
|
for (int i = 0; i < names.length; i++) {
|
|
System.out.println(" " + (i + 1) + ". " + names[i]);
|
|
}
|
|
}
|
|
}
|
|
|