com.github.houbb.crawler.support.persist.impl.CrawlerPersistCsv Maven / Gradle / Ivy
package com.github.houbb.crawler.support.persist.impl;
import com.github.houbb.crawler.support.persist.ICrawlerPersist;
import com.github.houbb.csv.util.CsvHelper;
import com.github.houbb.heaven.annotation.ThreadSafe;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.util.Collections;
/**
* 页面持久化-输出到 csv
*
* @author binbin.hou
* @since 0.0.3
*/
@ThreadSafe
public class CrawlerPersistCsv implements ICrawlerPersist {
/**
* 文件路径
* @since 0.0.3
*/
private final String path;
public CrawlerPersistCsv(String path) {
this.path = path;
}
/**
* 结果转换处理
*
* @param document 当前文档
* @param element 元素信息
* @param result 结果类
* @since 0.0.3
*/
@Override
public void persist(final Document document,
final Element element,
final Object result) {
CsvHelper.write(Collections.singletonList(result), path);
}
}