当前位置: 首页>>代码示例>>Java>>正文


Java CrawlController.shutdown方法代码示例

本文整理汇总了Java中edu.uci.ics.crawler4j.crawler.CrawlController.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java CrawlController.shutdown方法的具体用法?Java CrawlController.shutdown怎么用?Java CrawlController.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uci.ics.crawler4j.crawler.CrawlController的用法示例。


在下文中一共展示了CrawlController.shutdown方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import edu.uci.ics.crawler4j.crawler.CrawlController; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	if (args.length != 2) {
		System.out.println("Needed parameters: ");
		System.out.println("\t rootFolder (it will contain intermediate crawl data)");
		System.out.println("\t numberOfCralwers (number of concurrent threads)");
		return;
	}

	/*
	 * crawlStorageFolder is a folder where intermediate crawl data is
	 * stored.
	 */
	String crawlStorageFolder = args[0];

	/*
	 * numberOfCrawlers shows the number of concurrent threads that should
	 * be initiated for crawling.
	 */
	int numberOfCrawlers = Integer.parseInt(args[1]);

	CrawlConfig config = new CrawlConfig();

	config.crawlStorageFolder_$eq(crawlStorageFolder);

	config.politenessDelay_$eq(1000);

	// Unlimited number of pages can be crawled.
	config.maxPagesToFetch_$eq(-1);

	/*
	 * Instantiate the controller for this crawl.
	 */
	PageFetcher pageFetcher = new PageFetcher(config);
	RobotsTxtConfig robotstxtConfig = new RobotsTxtConfig();
	RobotsTxtServer robotstxtServer = new RobotsTxtServer(robotstxtConfig, pageFetcher);
	CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);

	/*
	 * For each crawl, you need to add some seed urls. These are the first
	 * URLs that are fetched and then the crawler starts following links
	 * which are found in these pages
	 */
	controller.addSeed("http://www.ics.uci.edu/~welling/");
	controller.addSeed("http://www.ics.uci.edu/~lopes/");
	controller.addSeed("http://www.ics.uci.edu/");

	/*
	 * Start the crawl. This is a blocking operation, meaning that your code
	 * will reach the line after this only when crawling is finished.
	 */
	controller.startNonBlocking(BasicCrawler.class, numberOfCrawlers);

	// Wait for 30 seconds
	Thread.sleep(30 * 1000);

	// Send the shutdown request and then wait for finishing
	controller.shutdown();
	controller.waitUntilFinish();
}
 
开发者ID:sapienapps,项目名称:scrawler,代码行数:60,代码来源:ControllerWithShutdown.java

示例2: main

import edu.uci.ics.crawler4j.crawler.CrawlController; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	if (args.length != 2) {
		System.out.println("Needed parameters: ");
		System.out.println("\t rootFolder (it will contain intermediate crawl data)");
		System.out.println("\t numberOfCralwers (number of concurrent threads)");
		return;
	}

	/*
	 * crawlStorageFolder is a folder where intermediate crawl data is
	 * stored.
	 */
	String crawlStorageFolder = args[0];

	/*
	 * numberOfCrawlers shows the number of concurrent threads that should
	 * be initiated for crawling.
	 */
	int numberOfCrawlers = Integer.parseInt(args[1]);

	CrawlConfig config = new CrawlConfig();

	config.setCrawlStorageFolder(crawlStorageFolder);

	config.setPolitenessDelay(1000);

	// Unlimited number of pages can be crawled.
	config.setMaxPagesToFetch(-1);

	/*
	 * Instantiate the controller for this crawl.
	 */
	PageFetcher pageFetcher = new PageFetcher(config);
	RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
	RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
	CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);

	/*
	 * For each crawl, you need to add some seed urls. These are the first
	 * URLs that are fetched and then the crawler starts following links
	 * which are found in these pages
	 */
	controller.addSeed("http://www.ics.uci.edu/~welling/");
	controller.addSeed("http://www.ics.uci.edu/~lopes/");
	controller.addSeed("http://www.ics.uci.edu/");

	/*
	 * Start the crawl. This is a blocking operation, meaning that your code
	 * will reach the line after this only when crawling is finished.
	 */
	controller.startNonBlocking(BasicCrawler.class, numberOfCrawlers);

	// Wait for 30 seconds
	Thread.sleep(30 * 1000);

	// Send the shutdown request and then wait for finishing
	controller.shutdown();
	controller.waitUntilFinish();
}
 
开发者ID:Chaiavi,项目名称:Crawler4j,代码行数:60,代码来源:ControllerWithShutdown.java


注:本文中的edu.uci.ics.crawler4j.crawler.CrawlController.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。