urllogger.java

来自「一个Java的网络爬虫」· Java 代码 · 共 38 行

JAVA
38
字号
package net.matuschek.http;

import java.io.IOException;
import java.io.Writer;
/*********************************************
    Copyright (c) 2001 by Daniel Matuschek
*********************************************/


/**
 * Simple document manager that logs the URL of the document to
 * a given Writer
 *
 * @author Daniel Matuschek 
 * @version $Revision: 1.4 $
 */
public class URLLogger extends AbstractHttpDocManager {
  
  /** Writer to write to */
  private Writer wr;

  public URLLogger(Writer wr) {
    this.wr = wr;
  }

  public void processDocument(HttpDoc doc) 
    throws DocManagerException 
  {
    try {
      wr.write(doc.getURL().toString());
      wr.write("\n");
    } catch (IOException e) {
      throw new DocManagerException("IOError: "+e.getMessage());
    }
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?