# monkey **Repository Path**: wangsihong/monkey ## Basic Information - **Project Name**: monkey - **Description**: monkey 分布式爬虫框架 - **Primary Language**: Scala - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2016-10-08 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### Monkey `0.5.0` ###### 基于Spark核心代码改写的爬虫,添加了爬虫相关代码,添加extract操作来封装数据爬取代码块。 --- #### 一个爬取小说的例子 ``` val conf = new MonkeyConf().setAppName("YourAppName") val context = new MonkeyContext(conf) // 这是一个爬取《斗罗大陆》小说的例子 // 构建 CrawlRequest 的 RDD 就可以在后面使用 extract 操作封装爬虫操作了 context.parallelize(Seq(CrawlRequest("http://www.1kanshu.cc/files/article/html/75/75486/"))) .extract(res => res).flatMap(p => { val html = new String(p.buffer, "GBK") val doc = Jsoup.parse(html) val linkeles = doc.select("div#list > dl > dd > a") for (i <- 0 until linkeles.size()) yield { val link = linkeles.get(i).attr("href") println(link) CrawlRequest(s"http://www.1kanshu.cc${link}", retryTimes = 2) } }).extract(res => res).map(p => { val html = new String(p.buffer, "GBK") val doc = Jsoup.parse(html) doc.select("div#content").text() }).saveAsTextFile("/your/save/path/douluodalu") ``` --- #### 编译 ``` //编译并打包为monkey-0.5.0-bin-2.5.0.tgz make-distribution.sh --tgz // 安装jar包到本地maven用来开发 cd monkey-0.5.0-bin-2.5.0 ./sbin/script/install-jar.sh // 启动集群前修改一些配置文件 // 配置文件再conf/下,大部分配 // 置和spark一样 // 启动集群 ./sbin/start-all.sh // 引入pom依赖 org.hong monkey 0.5.0 ``` 监控界面: http://localhost:8080