Skip to content

WebMagic-0.5.2

Compare
Choose a tag to compare
@code4craft code4craft released this 04 Jun 14:20
· 673 commits to develop since this release

此次主要包括对于Selector部分的重构,以及一些功能的完善和一些Bugfix。

  • 重构了Selector部分,使得结构更清晰,并且能够更好的支持链式的XPath抽取了。 [Issue #113]

  • 支持对于选取出来的结果,进行外部迭代。例如:

    List<Selectable> divs = html.xpath("//div").nodes();
    for (Selectable div : divs) {
        System.out.println(div.xpath("//h2").get());
    }
  • 增强自动编码识别机制,现在除了从HTTP头中,还会从HTML Meta信息中判断编码,感谢@fengwuze @sebastian1118提交代码和建议。[Issue #126]

  • 升级Xsoup版本为0.2.4,增加了判断XPath最终抽取结果(是元素还是属性)的API,完善了一些特殊字符处理的功能。

  • 增加PageMapper功能,以后可以在任何地方使用注解模式来解析页面了![Issue #120] 例如:

    public void process(Page page) {
            //新建Mapper,GithubRepo是一个带注解的POJO
            PageMapper<GithubRepo> githubRepoPageMapper = new PageMapper<GithubRepo>(GithubRepo.class);
            //直接解析页面,得到解析后的结果
            GithubRepo githubRepo = githubRepoPageMapper.get(page);
            page.putField("repo",githubRepo);
        }
  • 增加多个代理以及智能切换的支持,感谢@yxssfxwzy 贡献代码,使用Site.setHttpProxyPool可开启此功能。[Pull #128]

    public void process(Page page) {
            Site site = Site.me().setHttpProxyPool(
                    Lists.newArrayList(
                            new String[]{"192.168.0.2","8080"},
                            new String[]{"192.168.0.3","8080"}));
        }

Bugfix:

  • 修复了JsonFilePipeline不能自动创建文件夹的问题。[Issue #122]
  • 修复了Jsonp在removePadding时,对于特殊字符匹配不当的问题。[Issue #124]
  • 修复了当JsonPathSelector选取的结果是非String类型时,类型转换出错的问题。[Issue #129]