分享

MapReduce中使用HTMLunit实现爬虫出现java.lang.NoSuchFieldError: INSTANCE

//主要功能是从hbase中读一条URL执行,很简单的代码:

public static class CrawlReducer
                extends TableReducer<Text, IntWritable, NullWritable>{
                @Override
                protected void reduce(Text key, Iterable<IntWritable> value, Context context)
                        throws IOException, InterruptedException{
               
                        Put put = new Put(Bytes.toBytes(key.toString()));
                        put.add(Bytes.toBytes("content"), Bytes.toBytes("html"),
                                        Bytes.toBytes(startCrawl(key.toString())));
                        context.write(NullWritable.get(), put);
                }
        }

        public static String startCrawl(String url){
                WebClient webClient = new WebClient(BrowserVersion.CHROME);
                webClient.getOptions().setCssEnabled(false);
                webClient.getOptions().setJavaScriptEnabled(true);
                webClient.getOptions().setThrowExceptionOnScriptError(false);
                webClient.setAjaxController(new NicelyResynchronizingAjaxController());
                webClient.getOptions().setTimeout(5000);
               
                HtmlPage page = null;
                try {
                        page = webClient.getPage(url);//运行到此就错误、、、、、、、、、、、、、、、、、、、、、、、、、、
                        Thread.sleep(5000);
                } catch (FailingHttpStatusCodeException e1) {
                        e1.printStackTrace();
                } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                } catch (IOException e1) {
                        e1.printStackTrace();
                } catch (Exception e) {
                        e.printStackTrace();
                }
                return page.getPage().asXml();
        }
独立运行都没错,但是把下载网页放入reduce就有错,瞎搞了两天没有解决,真郁闷。求大神告知解决方案,搜了MapReduce有什么主意事项基本没有,都是复制一大推Wordcount例子,无语。。。。。。。。
QQ截图20150902173055.png

已有(8)人评论

跳转到指定楼层
阿斯兰的 发表于 2015-9-2 17:44:07
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
回复

使用道具 举报

jixianqiuxue 发表于 2015-9-2 18:04:04
程序可能没有错的,而是被处理的文件字段与提取的字段没有对应上
回复

使用道具 举报

阿斯兰的 发表于 2015-9-2 18:33:22
jixianqiuxue 发表于 2015-9-2 18:04
程序可能没有错的,而是被处理的文件字段与提取的字段没有对应上

我有打印key.toString()看过是对的啊,而且我直接用链接测试page = webClient.getPage(“http://www.dianping.com”);这样也不行啊。reduce方法有没有什么限制?
回复

使用道具 举报

阿斯兰的 发表于 2015-9-2 18:56:04
人呢,快来人快来人快来人快来人快来人快来人快来人快来人快来人
回复

使用道具 举报

阿斯兰的 发表于 2015-9-2 18:57:46
jixianqiuxue 发表于 2015-9-2 18:04
程序可能没有错的,而是被处理的文件字段与提取的字段没有对应上

我打印过了,直接用链接执行都不行,HTMLunit代码放在reduce就不行
回复

使用道具 举报

langke93 发表于 2015-9-2 21:11:55
阿斯兰的 发表于 2015-9-2 18:57
我打印过了,直接用链接执行都不行,HTMLunit代码放在reduce就不行

是不是引用第三方包了,如果引用了,要在集群上都放上
回复

使用道具 举报

阿斯兰的 发表于 2015-9-3 20:05:32
langke93 发表于 2015-9-2 21:11
是不是引用第三方包了,如果引用了,要在集群上都放上

我是maven打包的jar,直接运行的。
回复

使用道具 举报

阿斯兰的 发表于 2015-9-5 19:38:32
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条