关于Heritrix的Extractor中文乱码

 

关键字:Heritrix 中文 乱码 GB2312 Extractor

 

继承从org.archive.crawler.extractor.Extractor的子类,在extract方法中可以从参数CrawlURI中取出要解析的内容。

 

curi.getHttpRecorder().getReplayCharSequence.toString()

 

有中文时,不做处理会输出乱码。可以在取到的HttpRecorder后设置编码:

 

HttpRecorder hr = curi.getHttpRecorder();

if ( hr == null ) {

    throw new IOException( "Why is recorder null here?" );

}

hr.setCharacterEncoding( "gb2312" );

cs = hr.getReplayCharSequence();

System.out.println( cs.toString() );


你可能感兴趣的:(编码,主题爬虫)