2 changed files with 51 additions and 0 deletions
@ -0,0 +1,15 @@ |
|||
package com.crawler; |
|||
|
|||
import com.crawler.command.CommandController; |
|||
|
|||
public class Main { |
|||
public static void main(String[] args) { |
|||
System.out.println("========================================"); |
|||
System.out.println("Java爬虫框架"); |
|||
System.out.println("========================================"); |
|||
System.out.println(); |
|||
|
|||
CommandController cmdController = new CommandController(); |
|||
cmdController.start(); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
package com.crawler; |
|||
|
|||
import com.crawler.controller.CrawlerController; |
|||
import com.crawler.crawler.Crawler; |
|||
import com.crawler.crawler.CrawlerFactory; |
|||
import com.crawler.model.CrawlerConfig; |
|||
|
|||
public class TestRunner { |
|||
public static void main(String[] args) { |
|||
CrawlerFactory factory = CrawlerFactory.getInstance(); |
|||
|
|||
String[] testUrls = { |
|||
"https://www.hnu.edu.cn", |
|||
"https://news.hnu.edu.cn", |
|||
"http://www.weather.com.cn", |
|||
"https://www.mountblade.com.cn" |
|||
}; |
|||
|
|||
for (String url : testUrls) { |
|||
System.out.println("========================================"); |
|||
System.out.println("测试 URL: " + url); |
|||
String crawlerName = factory.getCrawlerName(url); |
|||
System.out.println("选择爬虫: " + crawlerName); |
|||
|
|||
Crawler crawler = factory.createCrawler(url); |
|||
CrawlerConfig config = new CrawlerConfig(); |
|||
config.setTargetUrl(url); |
|||
|
|||
CrawlerController controller = new CrawlerController(crawler); |
|||
controller.setConfig(config); |
|||
controller.execute(); |
|||
|
|||
System.out.println(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue