Search in sources :

Example 1 with ConsolePipeline

use of us.codecraft.webmagic.pipeline.ConsolePipeline in project webmagic by code4craft.

the class Spider method initComponent.

protected void initComponent() {
    if (downloader == null) {
        this.downloader = new HttpClientDownloader();
    }
    if (pipelines.isEmpty()) {
        pipelines.add(new ConsolePipeline());
    }
    downloader.setThread(threadNum);
    if (threadPool == null || threadPool.isShutdown()) {
        if (executorService != null && !executorService.isShutdown()) {
            threadPool = new CountableThreadPool(threadNum, executorService);
        } else {
            threadPool = new CountableThreadPool(threadNum);
        }
    }
    if (startRequests != null) {
        for (Request request : startRequests) {
            addRequest(request);
        }
        startRequests.clear();
    }
    startTime = new Date();
}
Also used : HttpClientDownloader(us.codecraft.webmagic.downloader.HttpClientDownloader) ConsolePipeline(us.codecraft.webmagic.pipeline.ConsolePipeline) CountableThreadPool(us.codecraft.webmagic.thread.CountableThreadPool)

Example 2 with ConsolePipeline

use of us.codecraft.webmagic.pipeline.ConsolePipeline in project webmagic by code4craft.

the class QuickStarter method main.

public static void main(String[] args) {
    init();
    String key = null;
    key = readKey(key);
    System.out.println("The demo started and will last 20 seconds...");
    // Start spider
    OOSpider.create(Site.me(), clazzMap.get(key)).addUrl(urlMap.get(key)).addPipeline(new MultiPagePipeline()).addPipeline(new ConsolePipeline()).runAsync();
    try {
        Thread.sleep(20000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("The demo stopped!");
    System.out.println("To more usage, try to customize your own Spider!");
    System.exit(0);
}
Also used : ConsolePipeline(us.codecraft.webmagic.pipeline.ConsolePipeline) MultiPagePipeline(us.codecraft.webmagic.pipeline.MultiPagePipeline)

Aggregations

ConsolePipeline (us.codecraft.webmagic.pipeline.ConsolePipeline)2 HttpClientDownloader (us.codecraft.webmagic.downloader.HttpClientDownloader)1 MultiPagePipeline (us.codecraft.webmagic.pipeline.MultiPagePipeline)1 CountableThreadPool (us.codecraft.webmagic.thread.CountableThreadPool)1