在我的项目中,stormcrawler maven原型似乎不能很好地处理warc模块。目前,它只创建名称为“crawl-20180802121925-00000”的空0字节文件。warc.gz公司". 我是不是漏了什么?
我尝试通过创建一个默认项目来启用warc编写,如下所示:
mvn archetype:generate -DarchetypeGroupId=com.digitalpebble.stormcrawler -DarchetypeArtifactId=storm-crawler-archetype -DarchetypeVersion=1.10
然后在pom.xml文件就像这样
<dependency>
<groupId>com.digitalpebble.stormcrawler</groupId>
<artifactId>storm-crawler-warc</artifactId>
<version>1.10</version>
</dependency>
然后我将WARCHdfsBolt添加到fetch分组中,同时尝试写入本地文件系统目录。
public class CrawlTopology extends ConfigurableTopology {
public static void main(String[] args) throws Exception {
ConfigurableTopology.start(new CrawlTopology(), args);
}
@Override
protected int run(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
String[] testURLs = new String[] { "http://www.lequipe.fr/",
"http://www.lemonde.fr/", "http://www.bbc.co.uk/",
"http://storm.apache.org/", "http://digitalpebble.com/" };
builder.setSpout("spout", new MemorySpout(testURLs));
builder.setBolt("partitioner", new URLPartitionerBolt())
.shuffleGrouping("spout");
builder.setBolt("fetch", new FetcherBolt())
.fieldsGrouping("partitioner", new Fields("key"));
builder.setBolt("warc", getWarcBolt())
.localOrShuffleGrouping("fetch");
builder.setBolt("sitemap", new SiteMapParserBolt())
.localOrShuffleGrouping("fetch");
builder.setBolt("feeds", new FeedParserBolt())
.localOrShuffleGrouping("sitemap");
builder.setBolt("parse", new JSoupParserBolt())
.localOrShuffleGrouping("feeds");
builder.setBolt("index", new StdOutIndexer())
.localOrShuffleGrouping("parse");
Fields furl = new Fields("url");
// can also use MemoryStatusUpdater for simple recursive crawls
builder.setBolt("status", new StdOutStatusUpdater())
.fieldsGrouping("fetch", Constants.StatusStreamName, furl)
.fieldsGrouping("sitemap", Constants.StatusStreamName, furl)
.fieldsGrouping("feeds", Constants.StatusStreamName, furl)
.fieldsGrouping("parse", Constants.StatusStreamName, furl)
.fieldsGrouping("index", Constants.StatusStreamName, furl);
return submit("crawl", conf, builder);
}
private WARCHdfsBolt getWarcBolt() {
String warcFilePath = "/Users/user/Documents/workspace/test/warc";
FileNameFormat fileNameFormat = new WARCFileNameFormat()
.withPath(warcFilePath);
Map<String,String> fields = new HashMap<>();
fields.put("software:", "StormCrawler 1.0 http://stormcrawler.net/");
fields.put("conformsTo:", "http://www.archive.org/documents/WarcFileFormat-1.0.html");
WARCHdfsBolt warcbolt = (WARCHdfsBolt) new WARCHdfsBolt()
.withFileNameFormat(fileNameFormat);
warcbolt.withHeader(fields);
// can specify the filesystem - will use the local FS by default
// String fsURL = "hdfs://localhost:9000";
// warcbolt.withFsUrl(fsURL);
// a custom max length can be specified - 1 GB will be used as a default
FileSizeRotationPolicy rotpol = new FileSizeRotationPolicy(50.0f,
FileSizeRotationPolicy.Units.MB);
warcbolt.withRotationPolicy(rotpol);
return warcbolt;
}
}
不管我在本地运行它有没有通量,似乎都没有什么区别。您可以在此处查看演示回购:
https://github.com/keyboardsamurai/storm-test-warc