设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 软件追踪 查看内容

WebMagic 0.4.1 发布,Java 爬虫框架

2013-11-29 11:05| 发布者: 红黑魂| 查看: 3305| 评论: 0|来自: 开源中国

摘要: 此次更新加强了Ajax抓取的功能,并进行了一些功能改进。同时引入了重要的脚本化功能"webmagic-script",为今后的WebMagic-Avalon计划做准备。功能增强:修复了抓取完页面后,Spider偶尔无法退出的问题。详细问题的分 ...

此次更新加强了Ajax抓取的功能,并进行了一些功能改进。同时引入了重要的脚本化功能"webmagic-script",为今后的WebMagic-Avalon计划做准备。

功能增强:

  1. 修复了抓取完页面后,Spider偶尔无法退出的问题。详细问题的分析,有兴趣的可以点这里查看。
  2. 将抽取正文的SmartContentSelector中的算法改为哈工大的正文抽取算法https://code.google.com/p/cx-extractor/ ,经过测试,有较好的效果。 使用方法:Html.getSmartContent()
  3. 为Page加入了更多的Http信息,包括http状态码"Page.getStatusCode()"和未解析过的正文"Page.getRawText()"。
  4. 为Spider增加一些监控信息,包括抓取的页面数"Spider.getPageCount()",运行状态"Spider.getStatus()"和执行线程数"Spider.getThreadAlive()"。

Ajax方面,在注解模式,引入了JsonPath表达式来进行抽取,示例代码:

01public class AppStore {
02 
03    @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..trackName")
04    private String trackName;
05 
06    @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..description")
07    private String description;
08 
09    @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..userRatingCount")
10    private int userRatingCount;
11 
12    @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..screenshotUrls",multi = true)
13    private List<String> screenshotUrls;
14 
15    public static void main(String[] args) {
16        AppStore appStore = OOSpider.create(Site.me(), AppStore.class).<AppStore>get
(
"http://itunes.apple.com/lookup?id=653350791&country=cn&entity=software");
17        System.out.println(appStore.trackName);
18        System.out.println(appStore.description);
19        System.out.println(appStore.userRatingCount);
20        System.out.println(appStore.screenshotUrls);
21    }
22}

JsonPath表达式的含义及具体用法看这里:http://www.oschina.net/p/jsonpath

WebMagic今后的目标是一个完整的产品,让即使不会编码的人也能通过简单脚本,完成基本的爬虫开发,并促进脚本分享。这就是WebMagic-Avalon计划。大家可以查看https://github.com/code4craft/webmagic/issues/43 进行功能讨论,欢迎各种建议。

目前第一期是要做到脚本化,对应文档:

https://github.com/code4craft/webmagic/tree/master/webmagic-scripts

webmagic邮件组:https://groups.google.com/forum/#!forum/webmagic-java


酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部