From ce89ebb2b49d0053d3ec0523f80100fefa09a777 Mon Sep 17 00:00:00 2001 From: "yihua.huang" Date: Fri, 22 Jan 2016 10:49:36 +0800 Subject: [PATCH] remove en_doc zh_docs dir --- en_docs/README.md | 177 -------- zh_docs/README.md | 208 --------- zh_docs/us/codecraft/webmagic/Page-cmnt.xml | 91 ---- .../us/codecraft/webmagic/PagedModel-cmnt.xml | 14 - .../us/codecraft/webmagic/Request-cmnt.xml | 56 --- .../codecraft/webmagic/ResultItems-cmnt.xml | 27 -- zh_docs/us/codecraft/webmagic/Site-cmnt.xml | 147 ------- zh_docs/us/codecraft/webmagic/Spider-cmnt.xml | 90 ---- zh_docs/us/codecraft/webmagic/Task-cmnt.xml | 26 -- .../webmagic/downloader/Destroyable-cmnt.xml | 14 - .../webmagic/downloader/Downloader-cmnt.xml | 32 -- .../downloader/FileDownloader-cmnt.xml | 14 - .../downloader/HttpClientDownloader-cmnt.xml | 23 - .../downloader/HttpClientPool-cmnt.xml | 13 - .../webmagic/downloader/package.cmnt | 12 - .../webmagic/model/AfterExtractor-cmnt.xml | 15 - .../model/ConsolePageModelPipeline-cmnt.xml | 13 - .../codecraft/webmagic/model/HasKey-cmnt.xml | 24 - .../webmagic/model/OOSpider-cmnt.xml | 22 - .../webmagic/model/PageModelPipeline-cmnt.xml | 13 - .../model/annotation/ComboExtract-cmnt.xml | 13 - .../model/annotation/ExtractBy-cmnt.xml | 45 -- .../model/annotation/ExtractBy.Type-cmnt.xml | 6 - .../model/annotation/ExtractBy2-cmnt.xml | 15 - .../model/annotation/ExtractBy2.Type-cmnt.xml | 6 - .../model/annotation/ExtractBy3-cmnt.xml | 14 - .../model/annotation/ExtractBy3.Type-cmnt.xml | 6 - .../model/annotation/ExtractByRaw-cmnt.xml | 44 -- .../annotation/ExtractByRaw.Type-cmnt.xml | 6 - .../model/annotation/ExtractByUrl-cmnt.xml | 37 -- .../model/annotation/HelpUrl-cmnt.xml | 28 -- .../model/annotation/TargetUrl-cmnt.xml | 29 -- .../webmagic/model/annotation/package.cmnt | 12 - .../us/codecraft/webmagic/model/package.cmnt | 12 - zh_docs/us/codecraft/webmagic/package.cmnt | 17 - .../pipeline/ConsolePipeline-cmnt.xml | 15 - .../webmagic/pipeline/FilePipeline-cmnt.xml | 27 -- .../JsonFilePageModelPipeline-cmnt.xml | 28 -- .../pipeline/JsonFilePipeline-cmnt.xml | 27 -- .../webmagic/pipeline/PagedPipeline-cmnt.xml | 16 - .../webmagic/pipeline/Pipeline-cmnt.xml | 14 - .../codecraft/webmagic/pipeline/package.cmnt | 12 - .../webmagic/processor/PageProcessor-cmnt.xml | 27 -- .../processor/SimplePageProcessor-cmnt.xml | 14 - .../codecraft/webmagic/processor/package.cmnt | 12 - .../FileCacheQueueScheduler-cmnt.xml | 14 - .../scheduler/QueueScheduler-cmnt.xml | 14 - .../scheduler/RedisScheduler-cmnt.xml | 15 - .../webmagic/scheduler/Scheduler-cmnt.xml | 29 -- .../codecraft/webmagic/scheduler/package.cmnt | 12 - .../webmagic/selector/AndSelector-cmnt.xml | 13 - .../webmagic/selector/CssSelector-cmnt.xml | 14 - .../codecraft/webmagic/selector/Html-cmnt.xml | 14 - .../selector/JsonPathSelector-cmnt.xml | 13 - .../webmagic/selector/OrSelector-cmnt.xml | 13 - .../webmagic/selector/PlainText-cmnt.xml | 14 - .../webmagic/selector/RegexSelector-cmnt.xml | 14 - .../selector/ReplaceSelector-cmnt.xml | 14 - .../webmagic/selector/Selectable-cmnt.xml | 75 ---- .../webmagic/selector/Selector-cmnt.xml | 14 - .../selector/SelectorFactory-cmnt.xml | 14 - .../selector/SmartContentSelector-cmnt.xml | 15 - .../webmagic/selector/XpathSelector-cmnt.xml | 14 - .../codecraft/webmagic/selector/package.cmnt | 12 - .../webmagic/utils/DoubleKeyMap-cmnt.xml | 60 --- .../utils/FilePersistentBase-cmnt.xml | 15 - .../webmagic/utils/MultiKeyMapBase-cmnt.xml | 13 - .../webmagic/utils/ThreadUtils-cmnt.xml | 14 - .../webmagic/utils/UrlUtils-cmnt.xml | 22 - .../us/codecraft/webmagic/utils/package.cmnt | 12 - zh_docs/user-manual-new.md | 410 ------------------ 71 files changed, 2396 deletions(-) delete mode 100644 en_docs/README.md delete mode 100644 zh_docs/README.md delete mode 100644 zh_docs/us/codecraft/webmagic/Page-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/PagedModel-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/Request-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/ResultItems-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/Site-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/Spider-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/Task-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/Destroyable-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/Downloader-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/FileDownloader-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/HttpClientDownloader-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/HttpClientPool-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/downloader/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/model/AfterExtractor-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/ConsolePageModelPipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/HasKey-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/OOSpider-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/PageModelPipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ComboExtract-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy.Type-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2.Type-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3.Type-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw.Type-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/ExtractByUrl-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/HelpUrl-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/TargetUrl-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/model/annotation/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/model/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/ConsolePipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/FilePipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/JsonFilePageModelPipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/JsonFilePipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/PagedPipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/Pipeline-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/pipeline/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/processor/PageProcessor-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/processor/SimplePageProcessor-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/processor/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/scheduler/QueueScheduler-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/scheduler/RedisScheduler-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/scheduler/Scheduler-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/scheduler/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/selector/AndSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/CssSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/Html-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/JsonPathSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/OrSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/PlainText-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/RegexSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/ReplaceSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/Selectable-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/Selector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/SelectorFactory-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/SmartContentSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/XpathSelector-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/selector/package.cmnt delete mode 100644 zh_docs/us/codecraft/webmagic/utils/DoubleKeyMap-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/utils/FilePersistentBase-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/utils/MultiKeyMapBase-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/utils/ThreadUtils-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/utils/UrlUtils-cmnt.xml delete mode 100644 zh_docs/us/codecraft/webmagic/utils/package.cmnt delete mode 100644 zh_docs/user-manual-new.md diff --git a/en_docs/README.md b/en_docs/README.md deleted file mode 100644 index 5ae494c..0000000 --- a/en_docs/README.md +++ /dev/null @@ -1,177 +0,0 @@ -![logo](https://raw.github.com/code4craft/webmagic/master/assets/logo.jpg) - -[Readme in Chinese](https://github.com/code4craft/webmagic/tree/master/zh_docs) - -[User Manual (Chinese)](https://github.com/code4craft/webmagic/blob/master/user-manual.md) - - -[![Build Status](https://travis-ci.org/code4craft/webmagic.png?branch=master)](https://travis-ci.org/code4craft/webmagic) - ->A scalable crawler framework. It covers the whole lifecycle of crawler: downloading, url management, content extraction and persistent. It can simplify the development of a specific crawler. - -## Features: - -* Simple core with high flexibility. -* Simple API for html extracting. -* Annotation with POJO to customize a crawler, no configuration. -* Multi-thread and Distribution support. -* Easy to be integrated. - -## Install: - -Add dependencies to your pom.xml: - -```xml - - us.codecraft - webmagic-core - 0.5.1 - - - us.codecraft - webmagic-extension - 0.5.1 - -``` - -WebMagic use slf4j with slf4j-log4j12 implementation. If you customized your slf4j implementation, please exclude slf4j-log4j12. - -```xml - - - org.slf4j - slf4j-log4j12 - - -``` - - -## Get Started: - -### First crawler: - -Write a class implements PageProcessor. For example, I wrote a crawler of github repository infomation. - -```java -public class GithubRepoPageProcessor implements PageProcessor { - - private Site site = Site.me().setRetryTimes(3).setSleepTime(1000); - - @Override - public void process(Page page) { - page.addTargetRequests(page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()); - page.putField("author", page.getUrl().regex("https://github\\.com/(\\w+)/.*").toString()); - page.putField("name", page.getHtml().xpath("//h1[@class='entry-title public']/strong/a/text()").toString()); - if (page.getResultItems().get("name")==null){ - //skip this page - page.setSkip(true); - } - page.putField("readme", page.getHtml().xpath("//div[@id='readme']/tidyText()")); - } - - @Override - public Site getSite() { - return site; - } - - public static void main(String[] args) { - Spider.create(new GithubRepoPageProcessor()).addUrl("https://github.com/code4craft").thread(5).run(); - } -} -``` - -* `page.addTargetRequests(links)` - - Add urls for crawling. - -You can also use annotation way: - -```java -@TargetUrl("https://github.com/\\w+/\\w+") -@HelpUrl("https://github.com/\\w+") -public class GithubRepo { - - @ExtractBy(value = "//h1[@class='entry-title public']/strong/a/text()", notNull = true) - private String name; - - @ExtractByUrl("https://github\\.com/(\\w+)/.*") - private String author; - - @ExtractBy("//div[@id='readme']/tidyText()") - private String readme; - - public static void main(String[] args) { - OOSpider.create(Site.me().setSleepTime(1000) - , new ConsolePageModelPipeline(), GithubRepo.class) - .addUrl("https://github.com/code4craft").thread(5).run(); - } -} -``` - -### Docs and samples: - -Documents: [http://webmagic.io/docs/](http://webmagic.io/docs/) - -The architecture of webmagic (refered to [Scrapy](http://scrapy.org/)) - -![image](http://code4craft.github.io/images/posts/webmagic.png) - -Javadocs: [http://code4craft.github.io/webmagic/docs/en/](http://code4craft.github.io/webmagic/docs/en/) - -There are some samples in `webmagic-samples` package. - -### Lisence: - -Lisenced under [Apache 2.0 lisence](http://opensource.org/licenses/Apache-2.0) - -### Contributors: - -Thanks these people for commiting source code, reporting bugs or suggesting for new feature: - -* [ccliangbo](https://github.com/ccliangbo) -* [yuany](https://github.com/yuany) -* [yxssfxwzy](https://github.com/yxssfxwzy) -* [linkerlin](https://github.com/linkerlin) -* [d0ngw](https://github.com/d0ngw) -* [xuchaoo](https://github.com/xuchaoo) -* [supermicah](https://github.com/supermicah) -* [SimpleExpress](https://github.com/SimpleExpress) -* [aruanruan](https://github.com/aruanruan) -* [l1z2g9](https://github.com/l1z2g9) -* [zhegexiaohuozi](https://github.com/zhegexiaohuozi) -* [ywooer](https://github.com/ywooer) -* [yyw258520](https://github.com/yyw258520) -* [perfecking](https://github.com/perfecking) -* [lidongyang](http://my.oschina.net/lidongyang) -* [seveniu](https://github.com/seveniu) -* [sebastian1118](https://github.com/sebastian1118) -* [codev777](https://github.com/codev777) - - -### Thanks: - -To write webmagic, I refered to the projects below : - -* **Scrapy** - - A crawler framework in Python. - - [http://scrapy.org/](http://scrapy.org/) - -* **Spiderman** - - Another crawler framework in Java. - - [https://gitcafe.com/laiweiwei/Spiderman](https://gitcafe.com/laiweiwei/Spiderman) - -### Mail-list: - -[https://groups.google.com/forum/#!forum/webmagic-java](https://groups.google.com/forum/#!forum/webmagic-java) - -[http://list.qq.com/cgi-bin/qf_invite?id=023a01f505246785f77c5a5a9aff4e57ab20fcdde871e988](http://list.qq.com/cgi-bin/qf_invite?id=023a01f505246785f77c5a5a9aff4e57ab20fcdde871e988) - -QQ Group: 373225642 - - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/code4craft/webmagic/trend.png)](https://bitdeli.com/free "Bitdeli Badge") - diff --git a/zh_docs/README.md b/zh_docs/README.md deleted file mode 100644 index 2409bdb..0000000 --- a/zh_docs/README.md +++ /dev/null @@ -1,208 +0,0 @@ -![logo](https://raw.github.com/code4craft/webmagic/master/assets/logo.jpg) - - -[![Build Status](https://travis-ci.org/code4craft/webmagic.png?branch=master)](https://travis-ci.org/code4craft/webmagic) - - -[Readme in English](https://github.com/code4craft/webmagic/tree/master/en_docs) - -官方网站[http://webmagic.io/](http://webmagic.io/) - ->webmagic是一个开源的Java垂直爬虫框架,目标是简化爬虫的开发流程,让开发者专注于逻辑功能的开发。webmagic的核心非常简单,但是覆盖爬虫的整个流程,也是很好的学习爬虫开发的材料。作者曾经在前公司进行过一年的垂直爬虫的开发,webmagic就是为了解决爬虫开发的一些重复劳动而产生的框架。 - ->web爬虫是一种技术,webmagic致力于将这种技术的实现成本降低,但是出于对资源提供者的尊重,webmagic不会做反封锁的事情,包括:验证码破解、代理切换、自动登录等。 - -webmagic的主要特色: - -* 完全模块化的设计,强大的可扩展性。 -* 核心简单但是涵盖爬虫的全部流程,灵活而强大,也是学习爬虫入门的好材料。 -* 提供丰富的抽取页面API。 -* 无配置,但是可通过POJO+注解形式实现一个爬虫。 -* 支持多线程。 -* 支持分布式。 -* 支持爬取js动态渲染的页面。 -* 无框架依赖,可以灵活的嵌入到项目中去。 - -webmagic的架构和设计参考了以下两个项目,感谢以下两个项目的作者: - -python爬虫 **scrapy** [https://github.com/scrapy/scrapy](https://github.com/scrapy/scrapy) - -Java爬虫 **Spiderman** [https://gitcafe.com/laiweiwei/Spiderman](https://gitcafe.com/laiweiwei/Spiderman) - -webmagic的github地址:[https://github.com/code4craft/webmagic](https://github.com/code4craft/webmagic)。 - -## 快速开始 - -### 使用maven - -webmagic使用maven管理依赖,在项目中添加对应的依赖即可使用webmagic: - -```xml - - us.codecraft - webmagic-core - 0.5.2 - - - us.codecraft - webmagic-extension - 0.5.2 - -``` - -WebMagic 使用slf4j-log4j12作为slf4j的实现.如果你自己定制了slf4j的实现,请在项目中去掉此依赖。 - -```xml - - - org.slf4j - slf4j-log4j12 - - -``` - -#### 项目结构 - -webmagic主要包括两个包: - -* **webmagic-core** - - webmagic核心部分,只包含爬虫基本模块和基本抽取器。webmagic-core的目标是成为网页爬虫的一个教科书般的实现。 - -* **webmagic-extension** - - webmagic的扩展模块,提供一些更方便的编写爬虫的工具。包括注解格式定义爬虫、JSON、分布式等支持。 - -webmagic还包含两个可用的扩展包,因为这两个包都依赖了比较重量级的工具,所以从主要包中抽离出来,这些包需要下载源码后自己编译:: - -* **webmagic-saxon** - - webmagic与Saxon结合的模块。Saxon是一个XPath、XSLT的解析工具,webmagic依赖Saxon来进行XPath2.0语法解析支持。 - -* **webmagic-selenium** - - webmagic与Selenium结合的模块。Selenium是一个模拟浏览器进行页面渲染的工具,webmagic依赖Selenium进行动态页面的抓取。 - -在项目中,你可以根据需要依赖不同的包。 - -### 不使用maven - -在项目的**lib**目录下,有依赖的所有jar包,直接在IDE里import即可。 - -### 第一个爬虫 - -#### 定制PageProcessor - -PageProcessor是webmagic-core的一部分,定制一个PageProcessor即可实现自己的爬虫逻辑。以下是抓取osc博客的一段代码: - -```java -public class OschinaBlogPageProcesser implements PageProcessor { - - private Site site = Site.me().setDomain("my.oschina.net"); - - @Override - public void process(Page page) { - List links = page.getHtml().links().regex("http://my\\.oschina\\.net/flashsword/blog/\\d+").all(); - page.addTargetRequests(links); - page.putField("title", page.getHtml().xpath("//div[@class='BlogEntity']/div[@class='BlogTitle']/h1").toString()); - page.putField("content", page.getHtml().$("div.content").toString()); - page.putField("tags",page.getHtml().xpath("//div[@class='BlogTags']/a/text()").all()); - } - - @Override - public Site getSite() { - return site; - - } - - public static void main(String[] args) { - Spider.create(new OschinaBlogPageProcesser()).addUrl("http://my.oschina.net/flashsword/blog") - .addPipeline(new ConsolePipeline()).run(); - } -} -``` - - -这里通过page.addTargetRequests()方法来增加要抓取的URL,并通过page.putField()来保存抽取结果。page.getHtml().xpath()则是按照某个规则对结果进行抽取,这里抽取支持链式调用。调用结束后,toString()表示转化为单个String,all()则转化为一个String列表。 - -Spider是爬虫的入口类。Pipeline是结果输出和持久化的接口,这里ConsolePipeline表示结果输出到控制台。 - -执行这个main方法,即可在控制台看到抓取结果。webmagic默认有3秒抓取间隔,请耐心等待。 - -#### 使用注解 - -webmagic-extension包括了注解方式编写爬虫的方法,只需基于一个POJO增加注解即可完成一个爬虫。以下仍然是抓取oschina博客的一段代码,功能与OschinaBlogPageProcesser完全相同: - -```java -@TargetUrl("http://my.oschina.net/flashsword/blog/\\d+") -public class OschinaBlog { - - @ExtractBy("//title") - private String title; - - @ExtractBy(value = "div.BlogContent",type = ExtractBy.Type.Css) - private String content; - - @ExtractBy(value = "//div[@class='BlogTags']/a/text()", multi = true) - private List tags; - - public static void main(String[] args) { - OOSpider.create( - Site.me(), - new ConsolePageModelPipeline(), OschinaBlog.class).addUrl("http://my.oschina.net/flashsword/blog").run(); - } -} -``` - -这个例子定义了一个Model类,Model类的字段'title'、'content'、'tags'均为要抽取的属性。这个类在Pipeline里是可以复用的。 - -### 详细文档 - -见[http://webmagic.io/docs/](http://webmagic.io/docs/)。 - -### 示例 - -webmagic-samples目录里有一些定制PageProcessor以抽取不同站点的例子。 - -webmagic的使用可以参考:[oschina openapi 应用:博客搬家](http://my.oschina.net/oscfox/blog/194507) - - -### 协议 - -webmagic遵循[Apache 2.0协议](http://opensource.org/licenses/Apache-2.0) - -### 贡献者: - -以下是为WebMagic提交过代码或者issue的朋友: - -* [ccliangbo](https://github.com/ccliangbo) -* [yuany](https://github.com/yuany) -* [yxssfxwzy](https://github.com/yxssfxwzy) -* [linkerlin](https://github.com/linkerlin) -* [d0ngw](https://github.com/d0ngw) -* [xuchaoo](https://github.com/xuchaoo) -* [supermicah](https://github.com/supermicah) -* [SimpleExpress](https://github.com/SimpleExpress) -* [aruanruan](https://github.com/aruanruan) -* [l1z2g9](https://github.com/l1z2g9) -* [zhegexiaohuozi](https://github.com/zhegexiaohuozi) -* [ywooer](https://github.com/ywooer) -* [yyw258520](https://github.com/yyw258520) -* [perfecking](https://github.com/perfecking) -* [lidongyang](http://my.oschina.net/lidongyang) -* [seveniu](https://github.com/seveniu) -* [sebastian1118](https://github.com/sebastian1118) -* [codev777](https://github.com/codev777) -* [fengwuze](https://github.com/fengwuze) - -### 邮件组: - -Gmail: -[https://groups.google.com/forum/#!forum/webmagic-java](https://groups.google.com/forum/#!forum/webmagic-java) - -QQ: -[http://list.qq.com/cgi-bin/qf_invite?id=023a01f505246785f77c5a5a9aff4e57ab20fcdde871e988](http://list.qq.com/cgi-bin/qf_invite?id=023a01f505246785f77c5a5a9aff4e57ab20fcdde871e988) - -### QQ群: - -373225642 diff --git a/zh_docs/us/codecraft/webmagic/Page-cmnt.xml b/zh_docs/us/codecraft/webmagic/Page-cmnt.xml deleted file mode 100644 index 7ac44dc..0000000 --- a/zh_docs/us/codecraft/webmagic/Page-cmnt.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - Page保存了上一次抓取的结果,并可定义待抓取的链接内容。 - - 主要方法: - {@link #getUrl()} 获取页面的Url - {@link #getHtml()} 获取页面的html内容 - {@link #putField(String, Object)} 保存抽取的结果 - {@link #getResultItems()} 获取抽取的结果,在 {@link us.codecraft.webmagic.pipeline.Pipeline} 中调用 - {@link #addTargetRequests(java.util.List)} {@link #addTargetRequest(String)} 添加待抓取的链接 - - -
- Store extracted result and urls to be crawled.
-
-     Main method:
-     {@link #getUrl()} get url of current page
-     {@link #getHtml()}  get content of current page
-     {@link #putField(String, Object)}  save extracted result
-     {@link #getResultItems()} get extract results to be used in {@link us.codecraft.webmagic.pipeline.Pipeline}
-     {@link #addTargetRequests(java.util.List)} {@link #addTargetRequest(String)} add urls to fetch
-
- 
- - @author code4crafter@gmail.com
-]]>
-
- - - - - - - - - -)]]> - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/PagedModel-cmnt.xml b/zh_docs/us/codecraft/webmagic/PagedModel-cmnt.xml deleted file mode 100644 index 17ffd7a..0000000 --- a/zh_docs/us/codecraft/webmagic/PagedModel-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-8-4
- Time: 下午5:18
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/Request-cmnt.xml b/zh_docs/us/codecraft/webmagic/Request-cmnt.xml deleted file mode 100644 index 987da7b..0000000 --- a/zh_docs/us/codecraft/webmagic/Request-cmnt.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - Request对象封装了待抓取的url信息。
- 在PageProcessor中,Request对象可以通过{@link us.codecraft.webmagic.Page#getRequest()} 获取。
-
- Request对象包含一个extra属性,可以写入一些必须的上下文,这个特性在某些场合会有用。
-
-      Example:
-          抓取${linktext}时,希望提取链接link,并保存linktext的信息。
-      在上一个页面:
-      public void process(Page page){
-          Request request = new Request(link,linktext);
-          page.addTargetRequest(request)
-      }
-      在下一个页面:
-      public void process(Page page){
-          String linktext =  (String)page.getRequest().getExtra()[0];
-      }
- 
- - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午11:37 -]]>
-
- - - - - - - - 需扩展Scheduler
- 目前还没有对应支持优先级的Scheduler实现 =。=
- @param priority 优先级,越大则越靠前 - @return this -]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/ResultItems-cmnt.xml b/zh_docs/us/codecraft/webmagic/ResultItems-cmnt.xml deleted file mode 100644 index 7c7859c..0000000 --- a/zh_docs/us/codecraft/webmagic/ResultItems-cmnt.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-7-25
- Time: 下午12:20
-]]>
-
- - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/Site-cmnt.xml b/zh_docs/us/codecraft/webmagic/Site-cmnt.xml deleted file mode 100644 index 4f5d667..0000000 --- a/zh_docs/us/codecraft/webmagic/Site-cmnt.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - 这个类的所有getter方法,一般都只会被爬虫框架内部进行调用。
- - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午12:13 -]]>
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - 目前不支持多个域名的抓取。抓取多个域名请新建一个Spider。 - - @param domain 爬虫会抓取的域名 - @return this -]]> - - - - - 一般无需设置encoding,如果发现下载的结果是乱码,则可以设置此项。
- - @param charset 编码格式,主要是"utf-8"、"gbk"两种 - @return this -]]>
-
- - - - - -)]]> - - 默认为200,正常情况下,无须设置此项。
- 某些站点会错误的返回状态码,此时可以对这个选项进行设置。
- - @param acceptStatCode 可接受的状态码 - @return this -]]>
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/Spider-cmnt.xml b/zh_docs/us/codecraft/webmagic/Spider-cmnt.xml deleted file mode 100644 index 7004137..0000000 --- a/zh_docs/us/codecraft/webmagic/Spider-cmnt.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - webmagic爬虫的入口类。 - - 示例: - 定义一个最简单的爬虫: - Spider.create(new SimplePageProcessor("http://my.oschina.net/", "http://my.oschina.net/*blog/*")).run(); - - 使用FilePipeline保存结果到文件: - Spider.create(new SimplePageProcessor("http://my.oschina.net/", "http://my.oschina.net/*blog/*")) - .pipeline(new FilePipeline("/data/temp/webmagic/")).run(); - - 使用FileCacheQueueScheduler缓存URL,关闭爬虫后下次自动从停止的页面继续抓取: - Spider.create(new SimplePageProcessor("http://my.oschina.net/", "http://my.oschina.net/*blog/*")) - .scheduler(new FileCacheQueueScheduler("/data/temp/webmagic/cache/")).run(); - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午6:53 -]]>
-
- - - - - - - - - -)]]> - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/Task-cmnt.xml b/zh_docs/us/codecraft/webmagic/Task-cmnt.xml deleted file mode 100644 index d4f31dc..0000000 --- a/zh_docs/us/codecraft/webmagic/Task-cmnt.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-6-18 - Time: 下午2:57 -]]>
-
- - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/downloader/Destroyable-cmnt.xml b/zh_docs/us/codecraft/webmagic/downloader/Destroyable-cmnt.xml deleted file mode 100644 index 32cb949..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/Destroyable-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-7-26
- Time: 下午3:10
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/downloader/Downloader-cmnt.xml b/zh_docs/us/codecraft/webmagic/downloader/Downloader-cmnt.xml deleted file mode 100644 index 12277dc..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/Downloader-cmnt.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午12:14 -]]>
-
- - - - - - - - 如果不考虑多线程的可以不实现这个方法
- - @param thread 线程数量 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/downloader/FileDownloader-cmnt.xml b/zh_docs/us/codecraft/webmagic/downloader/FileDownloader-cmnt.xml deleted file mode 100644 index bd0d51b..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/FileDownloader-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - @author code4crafer@gmail.com - Date: 13-6-24 - Time: 上午7:24 -]]> - - diff --git a/zh_docs/us/codecraft/webmagic/downloader/HttpClientDownloader-cmnt.xml b/zh_docs/us/codecraft/webmagic/downloader/HttpClientDownloader-cmnt.xml deleted file mode 100644 index 3a02bc9..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/HttpClientDownloader-cmnt.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午12:15 -]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/downloader/HttpClientPool-cmnt.xml b/zh_docs/us/codecraft/webmagic/downloader/HttpClientPool-cmnt.xml deleted file mode 100644 index c1416d3..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/HttpClientPool-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - Date: 13-4-21 - Time: 下午12:29 -]]> - - diff --git a/zh_docs/us/codecraft/webmagic/downloader/package.cmnt b/zh_docs/us/codecraft/webmagic/downloader/package.cmnt deleted file mode 100644 index c2e3406..0000000 --- a/zh_docs/us/codecraft/webmagic/downloader/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/model/AfterExtractor-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/AfterExtractor-cmnt.xml deleted file mode 100644 index 8c272e6..0000000 --- a/zh_docs/us/codecraft/webmagic/model/AfterExtractor-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-3
- Time: 上午9:42
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/ConsolePageModelPipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/ConsolePageModelPipeline-cmnt.xml deleted file mode 100644 index 1549be7..0000000 --- a/zh_docs/us/codecraft/webmagic/model/ConsolePageModelPipeline-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-3
- Time: 下午3:41
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/HasKey-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/HasKey-cmnt.xml deleted file mode 100644 index 62debaf..0000000 --- a/zh_docs/us/codecraft/webmagic/model/HasKey-cmnt.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - 实现了这个接口的Model在输出时会使用getKey()作为标志(例如JsonFilePageModelPipeline中持久化的文件名)。
- 如果持久化的文件名是乱码,请再运行的环境变量里加上LANG=zh_CN.UTF-8 。
- - @author code4crafter@gmail.com
- Date: 13-8-10
- Time: 上午7:39
-]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/model/OOSpider-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/OOSpider-cmnt.xml deleted file mode 100644 index 232c509..0000000 --- a/zh_docs/us/codecraft/webmagic/model/OOSpider-cmnt.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-8-3
- Time: 上午9:51
-]]>
-
- - - - @param site - @param pageModelPipeline - @param pageModels -]]> - -
diff --git a/zh_docs/us/codecraft/webmagic/model/PageModelPipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/PageModelPipeline-cmnt.xml deleted file mode 100644 index 64fb524..0000000 --- a/zh_docs/us/codecraft/webmagic/model/PageModelPipeline-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-3
- Time: 上午9:34
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ComboExtract-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ComboExtract-cmnt.xml deleted file mode 100644 index 0c48851..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ComboExtract-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-16
- Time: 下午11:09
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy-cmnt.xml deleted file mode 100644 index 31d1257..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy-cmnt.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
- - - - - - - - - - - - - - - - 用于字段时,需要List来盛放结果
- 用于类时,表示单页抽取多个对象
- - @return 是否抽取多个结果 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy.Type-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy.Type-cmnt.xml deleted file mode 100644 index f0968be..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy.Type-cmnt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2-cmnt.xml deleted file mode 100644 index eaadafd..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2.Type-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2.Type-cmnt.xml deleted file mode 100644 index f0968be..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy2.Type-cmnt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3-cmnt.xml deleted file mode 100644 index 3bbaacb..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3.Type-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3.Type-cmnt.xml deleted file mode 100644 index f0968be..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractBy3.Type-cmnt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw-cmnt.xml deleted file mode 100644 index e266937..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw-cmnt.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
- - - - - - - - - - - - - - - - 需要List来盛放结果
- - @return 是否抽取多个结果 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw.Type-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw.Type-cmnt.xml deleted file mode 100644 index f0968be..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByRaw.Type-cmnt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByUrl-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByUrl-cmnt.xml deleted file mode 100644 index b97ae39..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/ExtractByUrl-cmnt.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
- - - - - - - - - - - - 用于字段时,需要List来盛放结果
- 用于类时,表示单页抽取多个对象
- - @return 是否抽取多个结果 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/HelpUrl-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/HelpUrl-cmnt.xml deleted file mode 100644 index e4eccb0..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/HelpUrl-cmnt.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
- - - - webmagic对正则表达式进行了修改,"."仅表示字符"."而不代表任意字符,而"\*"则代表了".\*",例如"http://\*.oschina.net/\*"代表了oschina所有的二级域名下的URL。
- - @return 抽取规则 -]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/TargetUrl-cmnt.xml b/zh_docs/us/codecraft/webmagic/model/annotation/TargetUrl-cmnt.xml deleted file mode 100644 index a2c86cf..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/TargetUrl-cmnt.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-1
- Time: 下午8:40
-]]>
-
- - - - webmagic对正则表达式进行了修改,"."仅表示字符"."而不代表任意字符,而"\*"则代表了".\*",例如"http://\*.oschina.net/\*"代表了oschina所有的二级域名下的URL。
- - @return 抽取规则 -]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/model/annotation/package.cmnt b/zh_docs/us/codecraft/webmagic/model/annotation/package.cmnt deleted file mode 100644 index 8405b97..0000000 --- a/zh_docs/us/codecraft/webmagic/model/annotation/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/model/package.cmnt b/zh_docs/us/codecraft/webmagic/model/package.cmnt deleted file mode 100644 index 9cffa3a..0000000 --- a/zh_docs/us/codecraft/webmagic/model/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/package.cmnt b/zh_docs/us/codecraft/webmagic/package.cmnt deleted file mode 100644 index 3ec8bc1..0000000 --- a/zh_docs/us/codecraft/webmagic/package.cmnt +++ /dev/null @@ -1,17 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - Main class "Spider" and models. - -
-包括webmagic入口类Spider和一些数据传递的实体类。 -
- ]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/pipeline/ConsolePipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/ConsolePipeline-cmnt.xml deleted file mode 100644 index e88c973..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/ConsolePipeline-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午1:45 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/pipeline/FilePipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/FilePipeline-cmnt.xml deleted file mode 100644 index 153c9e0..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/FilePipeline-cmnt.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-4-21 - Time: 下午6:28 -]]> - - - - - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePageModelPipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePageModelPipeline-cmnt.xml deleted file mode 100644 index 06509cf..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePageModelPipeline-cmnt.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - 如果持久化的文件名是乱码,请再运行的环境变量里加上LANG=zh_CN.UTF-8。
- - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午6:28 -]]>
-
- - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePipeline-cmnt.xml deleted file mode 100644 index 23993af..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/JsonFilePipeline-cmnt.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-4-21 - Time: 下午6:28 -]]> - - - - - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/pipeline/PagedPipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/PagedPipeline-cmnt.xml deleted file mode 100644 index 128521c..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/PagedPipeline-cmnt.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - 在使用redis做分布式爬虫时,请不要使用此功能。
- - @author code4crafter@gmail.com
- Date: 13-8-4
- Time: 下午5:15
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/pipeline/Pipeline-cmnt.xml b/zh_docs/us/codecraft/webmagic/pipeline/Pipeline-cmnt.xml deleted file mode 100644 index ac5552b..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/Pipeline-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-4-21 - Time: 下午1:39 -]]> - - diff --git a/zh_docs/us/codecraft/webmagic/pipeline/package.cmnt b/zh_docs/us/codecraft/webmagic/pipeline/package.cmnt deleted file mode 100644 index 656607e..0000000 --- a/zh_docs/us/codecraft/webmagic/pipeline/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/processor/PageProcessor-cmnt.xml b/zh_docs/us/codecraft/webmagic/processor/PageProcessor-cmnt.xml deleted file mode 100644 index 95c25dd..0000000 --- a/zh_docs/us/codecraft/webmagic/processor/PageProcessor-cmnt.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - extends the class to implements various spiders.
- @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午11:42 -]]>
-
- - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/processor/SimplePageProcessor-cmnt.xml b/zh_docs/us/codecraft/webmagic/processor/SimplePageProcessor-cmnt.xml deleted file mode 100644 index f2215ad..0000000 --- a/zh_docs/us/codecraft/webmagic/processor/SimplePageProcessor-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-22 - Time: 下午9:15 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/processor/package.cmnt b/zh_docs/us/codecraft/webmagic/processor/package.cmnt deleted file mode 100644 index 1f79cba..0000000 --- a/zh_docs/us/codecraft/webmagic/processor/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler-cmnt.xml b/zh_docs/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler-cmnt.xml deleted file mode 100644 index 539b359..0000000 --- a/zh_docs/us/codecraft/webmagic/scheduler/FileCacheQueueScheduler-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午1:13 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/scheduler/QueueScheduler-cmnt.xml b/zh_docs/us/codecraft/webmagic/scheduler/QueueScheduler-cmnt.xml deleted file mode 100644 index b217f0b..0000000 --- a/zh_docs/us/codecraft/webmagic/scheduler/QueueScheduler-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午1:13 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/scheduler/RedisScheduler-cmnt.xml b/zh_docs/us/codecraft/webmagic/scheduler/RedisScheduler-cmnt.xml deleted file mode 100644 index 41743a7..0000000 --- a/zh_docs/us/codecraft/webmagic/scheduler/RedisScheduler-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-7-25
- Time: 上午7:07
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/scheduler/Scheduler-cmnt.xml b/zh_docs/us/codecraft/webmagic/scheduler/Scheduler-cmnt.xml deleted file mode 100644 index fdf14dd..0000000 --- a/zh_docs/us/codecraft/webmagic/scheduler/Scheduler-cmnt.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Scheduler的接口包含一个Task参数,该参数是为单Scheduler多Task预留的(Spider就是一个Task)。
- @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午1:12 -]]>
-
- - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/scheduler/package.cmnt b/zh_docs/us/codecraft/webmagic/scheduler/package.cmnt deleted file mode 100644 index 8b8a9f1..0000000 --- a/zh_docs/us/codecraft/webmagic/scheduler/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/selector/AndSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/AndSelector-cmnt.xml deleted file mode 100644 index c9c4e02..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/AndSelector-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-3
- Time: 下午5:29
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/CssSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/CssSelector-cmnt.xml deleted file mode 100644 index 2092b3b..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/CssSelector-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午9:39 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/Html-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/Html-cmnt.xml deleted file mode 100644 index 1668cc5..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/Html-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午7:54 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/JsonPathSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/JsonPathSelector-cmnt.xml deleted file mode 100644 index f34d31b..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/JsonPathSelector-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-12
- Time: 下午12:54
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/OrSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/OrSelector-cmnt.xml deleted file mode 100644 index 7fb672e..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/OrSelector-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-8-3
- Time: 下午5:29
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/PlainText-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/PlainText-cmnt.xml deleted file mode 100644 index 15aba1c..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/PlainText-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午7:54 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/RegexSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/RegexSelector-cmnt.xml deleted file mode 100644 index 3d82c65..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/RegexSelector-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午7:09 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/ReplaceSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/ReplaceSelector-cmnt.xml deleted file mode 100644 index e96832f..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/ReplaceSelector-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午7:09 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/Selectable-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/Selectable-cmnt.xml deleted file mode 100644 index 73342fc..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/Selectable-cmnt.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-20 - Time: 下午7:51 -]]>
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/zh_docs/us/codecraft/webmagic/selector/Selector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/Selector-cmnt.xml deleted file mode 100644 index ee77b38..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/Selector-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-20 - Time: 下午8:02 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/SelectorFactory-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/SelectorFactory-cmnt.xml deleted file mode 100644 index 9741bc4..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/SelectorFactory-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午7:56 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/SmartContentSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/SmartContentSelector-cmnt.xml deleted file mode 100644 index c235de3..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/SmartContentSelector-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - Date: 13-4-21 - Time: 下午4:42 -]]> - - diff --git a/zh_docs/us/codecraft/webmagic/selector/XpathSelector-cmnt.xml b/zh_docs/us/codecraft/webmagic/selector/XpathSelector-cmnt.xml deleted file mode 100644 index e8343b9..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/XpathSelector-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 上午9:39 -]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/selector/package.cmnt b/zh_docs/us/codecraft/webmagic/selector/package.cmnt deleted file mode 100644 index dbcebb8..0000000 --- a/zh_docs/us/codecraft/webmagic/selector/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/utils/DoubleKeyMap-cmnt.xml b/zh_docs/us/codecraft/webmagic/utils/DoubleKeyMap-cmnt.xml deleted file mode 100644 index c8d2802..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/DoubleKeyMap-cmnt.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - ->, java.lang.Class)]]> - - - - - - - - - - - -)]]> - - - - - - - - - - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/utils/FilePersistentBase-cmnt.xml b/zh_docs/us/codecraft/webmagic/utils/FilePersistentBase-cmnt.xml deleted file mode 100644 index 62a48b9..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/FilePersistentBase-cmnt.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - @author code4crafter@gmail.com
- Date: 13-8-11
- Time: 下午4:21
-]]>
-
-
diff --git a/zh_docs/us/codecraft/webmagic/utils/MultiKeyMapBase-cmnt.xml b/zh_docs/us/codecraft/webmagic/utils/MultiKeyMapBase-cmnt.xml deleted file mode 100644 index 12162eb..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/MultiKeyMapBase-cmnt.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - - diff --git a/zh_docs/us/codecraft/webmagic/utils/ThreadUtils-cmnt.xml b/zh_docs/us/codecraft/webmagic/utils/ThreadUtils-cmnt.xml deleted file mode 100644 index fdf7aab..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/ThreadUtils-cmnt.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafer@gmail.com - Date: 13-6-23 - Time: 下午7:11 -]]> - - diff --git a/zh_docs/us/codecraft/webmagic/utils/UrlUtils-cmnt.xml b/zh_docs/us/codecraft/webmagic/utils/UrlUtils-cmnt.xml deleted file mode 100644 index 019523e..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/UrlUtils-cmnt.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - -Sat Aug 17 14:14:46 CST 2013 - - - - - @author code4crafter@gmail.com
- Date: 13-4-21 - Time: 下午1:52 -]]>
-
- - - - -
diff --git a/zh_docs/us/codecraft/webmagic/utils/package.cmnt b/zh_docs/us/codecraft/webmagic/utils/package.cmnt deleted file mode 100644 index 39b9703..0000000 --- a/zh_docs/us/codecraft/webmagic/utils/package.cmnt +++ /dev/null @@ -1,12 +0,0 @@ - - - -Sat Aug 17 14:14:45 CST 2013 - - - - - - diff --git a/zh_docs/user-manual-new.md b/zh_docs/user-manual-new.md deleted file mode 100644 index a8ae5c2..0000000 --- a/zh_docs/user-manual-new.md +++ /dev/null @@ -1,410 +0,0 @@ -WebMagic in Action -======== - -WebMagic是一个简单灵活、便于二次开发的爬虫框架。除了可以便捷的实现一个爬虫,WebMagic还提供多线程功能,以及基本的分布式功能。 - -你可以直接使用WebMagic进行爬虫开发,也可以定制WebMagic以适应复杂项目的需要。 - -## 1. 在项目中使用WebMagic - -WebMagic主要包含两个jar包:`webmagic-core-{version}.jar`和`webmagic-extension-{version}.jar`。在项目中添加这两个包的依赖,即可使用WebMagic。 - -### 1.1 使用Maven - -WebMagic基于Maven进行构建,推荐使用Maven来安装WebMagic。在项目中添加以下坐标即可: - -```xml - - us.codecraft - webmagic-extension - 0.4.3 - -``` - -WebMagic使用slf4j-log4j12作为slf4j的实现.如果你自己定制了slf4j的实现,请在项目中去掉此依赖。 - -```xml - - us.codecraft - webmagic-extension - 0.4.3 - - - org.slf4j - slf4j-log4j12 - - - -``` - -### 1.2 不使用Maven - -不使用maven的用户,可以下载附带二进制jar包的版本(感谢[oschina](http://www.oschina.net/)): - - git clone http://git.oschina.net/flashsword20/webmagic.git - -在**lib**目录下,有项目依赖的所有jar包,直接在IDE里,将这些jar添加到Libraries即可。 - -![import jars](http://static.oschina.net/uploads/space/2014/0403/143318_gBQE_190591.jpeg) - -### 1.3 第一个项目 - -在你的项目中添加了WebMagic的依赖之后,即可开始第一个爬虫的开发了!我们这里拿一个抓取Github信息的例子: - -```java -import us.codecraft.webmagic.Page; -import us.codecraft.webmagic.Site; -import us.codecraft.webmagic.Spider; -import us.codecraft.webmagic.processor.PageProcessor; - -public class GithubRepoPageProcessor implements PageProcessor { - - private Site site = Site.me().setRetryTimes(3).setSleepTime(100); - - @Override - public void process(Page page) { - page.addTargetRequests(page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()); - page.putField("author", page.getUrl().regex("https://github\\.com/(\\w+)/.*").toString()); - page.putField("name", page.getHtml().xpath("//h1[@class='entry-title public']/strong/a/text()").toString()); - if (page.getResultItems().get("name")==null){ - //skip this page - page.setSkip(true); - } - page.putField("readme", page.getHtml().xpath("//div[@id='readme']/tidyText()")); - } - - @Override - public Site getSite() { - return site; - } - - public static void main(String[] args) { - Spider.create(new GithubRepoPageProcessor()).addUrl("https://github.com/code4craft").thread(5).run(); - } -} -``` - -点击main方法,选择“运行”,你会发现爬虫已经可以正常工作了! - -![runlog](http://static.oschina.net/uploads/space/2014/0403/103741_3Gf5_190591.png) - -
- -## 2.下载和编译源码 - -WebMagic是一个纯Java项目,如果你熟悉Maven,那么下载并编译源码是非常简单的。如果不熟悉Maven也没关系,这部分会介绍如何在Eclipse里导入这个项目。 - -### 2.1 下载源码 - -WebMagic目前有两个仓库: - -* [https://github.com/code4craft/webmagic](https://github.com/code4craft/webmagic) - -github上的仓库保存最新版本,所有issue、pull request都在这里。大家觉得项目不错的话别忘了去给个star哦! - -* [http://git.oschina.net/flashsword20/webmagic](http://git.oschina.net/flashsword20/webmagic) - -此仓库包含所有编译好的依赖包,只保存项目的稳定版本,最新版本仍在github上更新。oschina在国内比较稳定,主要作为镜像。 - -无论在哪个仓库,使用 - - git clone https://github.com/code4craft/webmagic.git - -或者 - - git clone http://git.oschina.net/flashsword20/webmagic.git - -即可下载最新代码。 - -如果你对git本身使用也不熟悉,建议看看@黄勇的 [从 Git@OSC 下载 Smart 源码](http://my.oschina.net/huangyong/blog/200075) - -### 2.2 导入项目 - -Intellij Idea默认自带Maven支持,import项目时选择Maven项目即可。 - -#### 2.2.1 使用m2e插件 - -使用Eclipse的用户,推荐安装m2e插件,安装地址:https://www.eclipse.org/m2e/download/[](https://www.eclipse.org/m2e/download/) - -安装后,在File->Import中选择Maven->Existing Maven Projects即可导入项目。 - -![m2e-import](http://static.oschina.net/uploads/space/2014/0403/104427_eNuc_190591.png) - -导入后看到项目选择界面,点击finish即可。 - -![m2e-import2](http://static.oschina.net/uploads/space/2014/0403/104735_6vwG_190591.png) - -#### 2.2.2 使用Maven Eclipse插件 - -如果没有安装m2e插件,只要你安装了Maven,也是比较好办的。在项目根目录下使用命令: - - mvn eclipse:eclipse - -生成maven项目结构的eclipse配置文件,然后在File->Import中选择General->Existing Projects into Workspace即可导入项目。 - -![eclipse-import-1](http://static.oschina.net/uploads/space/2014/0403/100025_DAcy_190591.png) - -导入后看到项目选择界面,点击finish即可。 - -![eclipse-import-2](http://static.oschina.net/uploads/space/2014/0403/100227_73DJ_190591.png) - -### 2.3 编译和执行源码 - -导入成功之后,应该就没有编译错误了!此时你可以运行一下webmagic-core项目中自带的exmaple:"us.codecraft.webmagic.processor.example.GithubRepoPageProcessor"。 - -同样,看到控制台输出如下,则表示源码编译和执行成功了! - -![runlog](http://static.oschina.net/uploads/space/2014/0403/103741_3Gf5_190591.png) - -
- -## 3. 基本的爬虫 - -### 3.1 实现PageProcessor - -在WebMagic里,实现一个基本的爬虫只需要编写一个类,实现`PageProcessor`接口即可。这个类基本上包含了抓取一个网站,你需要写的所有代码。 - -以之前的`GithubRepoPageProcessor`为例,我将PageProcessor的定制分为三个部分,分别是爬虫的配置、页面元素的抽取和链接的发现。 - -```java -public class GithubRepoPageProcessor implements PageProcessor { - - // 部分一:抓取网站的相关配置,包括编码、抓取间隔、重试次数等 - private Site site = Site.me().setRetryTimes(3).setSleepTime(1000); - - @Override - // process是定制爬虫逻辑的核心接口,在这里编写抽取逻辑 - public void process(Page page) { - // 部分二:定义如何抽取页面信息,并保存下来 - page.putField("author", page.getUrl().regex("https://github\\.com/(\\w+)/.*").toString()); - page.putField("name", page.getHtml().xpath("//h1[@class='entry-title public']/strong/a/text()").toString()); - if (page.getResultItems().get("name") == null) { - //skip this page - page.setSkip(true); - } - page.putField("readme", page.getHtml().xpath("//div[@id='readme']/tidyText()")); - - // 部分三:从页面发现后续的url地址来抓取 - page.addTargetRequests(page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()); - } - - @Override - public Site getSite() { - return site; - } - - public static void main(String[] args) { - - Spider.create(new GithubRepoPageProcessor()) - //从"https://github.com/code4craft"开始抓 - .addUrl("https://github.com/code4craft") - //开启5个线程抓取 - .thread(5) - //启动爬虫 - .run(); - } -} -``` - -#### 3.1.1 爬虫的配置 - -第一部分关于爬虫的配置,包括编码、抓取间隔、超时时间、重试次数等,也包括一些模拟的参数,例如User Agent、cookie,以及代理的设置,我们会在第5章-“爬虫的配置”里进行介绍。在这里我们先简单设置一下:重试次数为3次,抓取间隔为一秒。 - -#### 3.1.2 页面元素的抽取 - -第二部分是爬虫的核心部分:对于下载到的Html页面,你如何从中抽取到你想要的信息?WebMagic里主要使用了三种抽取技术:XPath、正则表达式和CSS选择器。 - -1. XPath - - XPath本来是用于XML中获取元素的一种查询语言,但是用于Html也是比较方便的。例如: - - ```java - page.getHtml().xpath("//h1[@class='entry-title public']/strong/a/text()") - ``` - 这段代码使用了XPath,它的意思是“查找所有class属性为'entry-title public'的h1元素,并找到他的strong子节点的a子节点,并提取a节点的文本信息”。 -对应的Html是这样子的: - - ![xpath-html](http://static.oschina.net/uploads/space/2014/0404/104607_Aqq8_190591.png) - -2. CSS选择器 - - CSS选择器是与XPath类似的语言。如果大家做过前端开发,肯定知道$('h1.entry-title')这种写法的含义。客观的说,它比XPath写起来要简单一些,但是如果写复杂一点的抽取规则,就相对要麻烦一点。 - -3. 正则表达式 - - 正则表达式则是一种通用的文本抽取语言。 - - ```java - page.addTargetRequests(page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()); - ``` - - 这段代码就用到了正则表达式,它表示匹配所有"https://github.com/code4craft/webmagic"这样的链接。 - -XPath、CSS选择器和正则表达式的具体用法会在第4章“抽取工具详解”中讲到。 - -#### 3.1.3 链接的发现 - -有了处理页面的逻辑,我们的爬虫就接近完工了! - -但是现在还有一个问题:一个站点的页面是很多的,一开始我们不可能全部列举出来,于是如何发现后续的链接,是一个爬虫不可缺少的一部分。 - -```java -page.addTargetRequests(page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()); -``` - -这段代码的分为两部分,`page.getHtml().links().regex("(https://github\\.com/\\w+/\\w+)").all()`用于获取所有满足"(https://github\\.com/\\w+/\\w+)"这个正则表达式的链接,`page.addTargetRequests()`则将这些链接加入到待抓取的队列中去。 - -### 3.2 使用Selectable的链式API - -`Selectable`相关的链式API是WebMagic的一个核心功能。使用Selectable接口,你可以直接完成页面元素的链式抽取,也无需去关心抽取的细节。 - -在刚才的例子中可以看到,page.getHtml()返回的是一个`Html`对象,它实现了`Selectable`接口。这个接口包含一些重要的方法,我将它分为两类:抽取部分和获取结果部分。 - -#### 3.2.1 抽取部分API: - -| 方法 | 说明 | 示例 | -| ------------ | ------------- | ------------ | -| xpath(String xpath) | 使用XPath选择 | html.xpath("//div[@class='title']") | -| \$(String selector) | 使用Css选择器选择 | html.\$("div.title") | -| \$(String selector,String attr) | 使用Css选择器选择 | html.\$("div.title","text") | -| css(String selector) | 功能同$(),使用Css选择器选择 | html.css("div.title") | -| links() | 选择所有链接 | html.links() | -| regex(String regex) | 使用正则表达式抽取 | html.regex("\(.\*?)\") | -| regex(String regex,int group) | 使用正则表达式抽取,并指定捕获组 | html.regex("\(.\*?)\",1) | -| replace(String regex, String replacement) | 替换内容| html.replace("\","")| - -这部分抽取API返回的都是一个`Selectable`接口,意思是说,抽取是支持链式调用的。下面我用一个实例来讲解链式API的使用。 - -例如,我现在要抓取github上所有的Java项目,这些项目可以在[https://github.com/search?l=Java&p=1&q=stars%3A%3E1&s=stars&type=Repositories](https://github.com/search?l=Java&p=1&q=stars%3A%3E1&s=stars&type=Repositories)搜索结果中看到。 - -为了避免抓取范围太宽,我指定只从分页部分抓取链接。这个抓取规则是比较复杂的,我会要怎么写呢? - -![selectable-chain-ui](http://static.oschina.net/uploads/space/2014/0404/151454_2T01_190591.png) - -首先看到页面的html结构是这个样子的: - -![selectable-chain](http://static.oschina.net/uploads/space/2014/0404/151632_88Oq_190591.png) - -那么我可以先用CSS选择器提取出这个div,然后在取到所有的链接。为了保险起见,我再使用正则表达式限定一下提取出的URL的格式,那么最终的写法是这样子的: - -```java -List urls = page.getHtml().css("div.pagination").links().regex(".*/search/\?l=java.*").all(); -``` - -然后,我们可以把这些URL加到抓取列表中去: - -```java -List urls = page.getHtml().css("div.pagination").links().regex(".*/search/\?l=java.*").all(); -page.addTargetRequests(urls); -``` - -是不是比较简单?除了发现链接,Selectable的链式抽取还可以完成很多工作。我们会在第9章示例中再讲到。 - -#### 3.2.2 获取结果的API: - -当链式调用结束时,我们一般都想要拿到一个字符串类型的结果。这时候就需要用到获取结果的API了。我们知道,一条抽取规则,无论是XPath、CSS选择器或者正则表达式,总有可能抽取到多条元素。WebMagic对这些进行了统一,你可以通过不同的API获取到一个或者多个元素。 - -| 方法 | 说明 | 示例 | -| ------------ | ------------- | ------------ | -| get() | 返回一条String类型的结果 | String link= html.links().get()| -| toString() | 功能同get(),返回一条String类型的结果 | String link= html.links().toString()| -| all() | 返回所有抽取结果 | List links= html.links().all()| -| match() | 是否有匹配结果 | if (html.links().match()){ xxx; }| - -例如,我们知道页面只会有一条结果,那么可以使用selectable.get()或者selectable.toString()拿到这条结果。 - -这里selectable.toString()采用了toString()这个接口,是为了在输出以及和一些框架结合的时候,更加方便。因为一般情况下,我们都只需要选择一个元素! - -selectable.all()则会获取到所有元素。 - -好了,到现在为止,在回过头看看3.1中的GithubRepoPageProcessor,可能就觉得更加清晰了吧?指定main方法,已经可以看到抓取结果在控制台输出了。 - -### 3.3 保存结果 - -好了,爬虫编写完成,现在我们可能还有一个问题:我如果想把抓取的结果保存下来,要怎么做呢?WebMagic用于保存结果的组件叫做`Pipeline`。例如我们通过“控制台输出结果”这件事也是通过一个内置的Pipeline完成的,它叫做`ConsolePipeline`。那么,我现在想要把结果用Json的格式保存下来,怎么做呢?我只需要将Pipeline的实现换成"JsonFilePipeline"就可以了。 - -```java - public static void main(String[] args) { - - Spider.create(new GithubRepoPageProcessor()) - //从"https://github.com/code4craft"开始抓 - .addUrl("https://github.com/code4craft") - .addPipeline(new JsonFilePipeline("D:\webmagic\")) - //开启5个线程抓取 - .thread(5) - //启动爬虫 - .run(); - } -``` - -这样子下载下来的文件就会保存在D盘的webmagic目录中了。 - -通过定制Pipeline,我们还可以实现保存结果到文件、数据库等一系列功能。这个会在第7章“抽取结果的处理”中介绍。 - -至此为止,我们已经完成了一个基本爬虫的编写,也具有了一些定制功能。 - -
- -## 4. 抽取工具详解 - -### 4.1 XPath - -### 4.2 CSS选择器 - -### 4.3 正则表达式 - -### 4.4 JsonPath - -## 5. 配置爬虫 - -### 5.1 抓取频率 - -### 5.2 编码 - -### 5.3 代理 - -### 5.4 设置cookie/UA等http头信息 - -### 5.5 重试机制 - -### 5.6 多线程 - -## 6. 爬虫的启动和终止 - -### 6.1 启动爬虫 - -### 6.2 终止爬虫 - -### 6.3 设置执行时间 - -### 6.4 定期抓取 - -## 7. 抽取结果的处理 - -### 7.1 输出到控制台 - -### 7.2 保存到文件 - -### 7.3 JSON格式输出 - -### 7.4 自定义持久化方式(mysql/mongodb…) - -## 8. 管理URL - -### 8.1 手动添加URL - -### 8.2 在URL中保存信息 - -### 8.3 几种URL管理方式 - -### 8.4 自己管理爬虫的URL - -## 9. 实例 - -### 9.1 基本的列表+详情页的抓取 - -### 9.2 抓取动态页面 - -### 9.3 分页抓取 - -### 9.4 定期抓取 \ No newline at end of file