Exception in thread "Spider-0" java.lang.NullPointerException - Gecco爬虫心得

使用Gecco爬虫时偶尔遇到如下莫名其妙的异常而停止:

Exception in thread "Spider-0" java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
    at java.util.regex.Matcher.reset(Matcher.java:309)
    at java.util.regex.Matcher.<init>(Matcher.java:229)
    at java.util.regex.Pattern.matcher(Pattern.java:1093)
    at com.geccocrawler.gecco.utils.UrlMatcher.match(UrlMatcher.java:80)
    at com.geccocrawler.gecco.spider.SpiderBeanFactory.matchSpider(SpiderBeanFactory.java:112)
    at com.geccocrawler.gecco.spider.Spider.run(Spider.java:68)
    at java.lang.Thread.run(Thread.java:745)

后来细心查看才发现(SpiderBeanFactory.java:112)中,空指针调用的url地址是来自 request

 
于是做了如下测试:
HttpGetRequest start = new HttpGetRequest(null);
GeccoEngine.create()
        .classpath("com.example.crawler")
        .start(start)
        .interval(2000)
        .run();

由此可知,是爬虫过程中如下的调用没有保证url不为null

HttpRequest sub = l.getRequest().subRequest(url);
SchedulerContext.into(sub);

个人原创:爱我子月

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值