zoukankan      html  css  js  c++  java
  • 读取nutch爬取内容方法

    读取nutch内容有如下两种方法:

    1 通过Nutch api SegmentReader读取。

             public Content readSegment(String segPath,String url){  

                  
                Text key= new Text(url);  
                Path path= new Path(segPath);  
                Content content = null;  
          
                ArrayList<Writable> parsedLst = null;  
                Map<String,List<Writable>> results=new HashMap<String, List<Writable>>();  
                SegmentReader reader= new SegmentReader(configuration,true,true,true,true,true,true);  
                try {  
                    reader.get(path, key, new StringWriter(), results);  
                    parsedLst=(ArrayList<Writable>) results.get("co");  
                    Iterator<Writable> parseIter=parsedLst.iterator();  
                    while(parseIter.hasNext()){  
                        content=(Content) parseIter.next();  
                    }  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
          
                return content;  

            }  

      2 通过SequenceFile 读取

            public static void main(String[] args) throws IOException { 

                args=new String[]{"D:\nutchv\nutch12\apache-nutch-1.2\data\csdn2\segments\20140904104348"};   

                Configuration conf = NutchConfiguration.create();       
                Options opts = new Options();       
                GenericOptionsParser parser = new GenericOptionsParser(conf, opts, args);       
                String[] remainingArgs = parser.getRemainingArgs();     
                FileSystem fs = FileSystem.get(conf);
                String segment = remainingArgs[0];
                Path file = new Path(segment, Content.DIR_NAME + "/part-00000/data");
                SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf);
                Text key = new Text();
                Content content = new Content();
                // Loop through sequence files
                while (reader.next(key, content)) {
                    try {
                        System.out.write(content.getContent(), 0,
                                content.getContent().length);
                    } catch (Exception e) {
                    }
                }

            } 

  • 相关阅读:
    The last access date is not changed even after reading the file on Windows 7
    渗透基础——获得当前系统已安装的程序列表
    Top 10 Best Free Netflow Analyzers and Collectors for Windows
    平安科技移动开发二队技术周报(第十五期)
    Intent传递对象的几种方式
    SQLite基础学习
    2 Java基础语法(keyword,标识符,凝视,常量,进制转换,变量,数据类型,数据类型转换)
    iOS 之应用性能调优的25个建议和技巧
    Fragment事务管理源代码分析
    CMake
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/3957359.html
Copyright © 2011-2022 走看看