zoukankan      html  css  js  c++  java
  • java爬虫框架webmagic学习(一)

    1. 爬虫的分类:分布式和单机

        分布式主要就是apache的nutch框架,java实现,依赖hadoop运行,学习难度高,一般只用来做搜索引擎开发。

        java单机的框架有:webmagic和webcollector以及crawler4j

        python单机的框架:scrapy和pyspider

    2. 作者自己在官方教程也说到了“WebMagic的设计参考了业界最优秀的爬虫Scrapy”,说明精通scrapy还是爬虫工程师最重要的任务。

    3. WebMagic的代码分为两部分:webmagic-core和webmagic-extension

    4. WebMagic由四个组件(Downloader、PageProcessor、Scheduler、Pipeline)构成。Spider是内部流程的核心,四大组件都是它的属性。

        Spider也是WebMagic操作的入口,它封装了爬虫的创建、启动、停止、多线程等功能。

    5. public static void main(String[] args){

         Spider.create(new GithubRepoPageProcessor()) //从https://github.com/code4craft开始抓

            .addUrl("https://github.com/code4craft") //设置Scheduler,使用Redis来管理URL队列

            .setScheduler(new RedisScheduler("localhost")) //设置Pipeline,将结果以json方式保存到文件

            .addPipeline(new JsonFilePipeline("D:\data\webmagic")) //开启5个线程同时执行 .thread(5) //启动爬虫

            .run();

      }

    6. webmagic-selenium支持动态网页的爬取,webmagic-saxon支持X-Path和XSLT的解析。

  • 相关阅读:
    Redis
    Redis
    运维
    Redis
    Redis
    Redis
    Redis
    Redis
    Redis
    Spring
  • 原文地址:https://www.cnblogs.com/jdbc2nju/p/9309172.html
Copyright © 2011-2022 走看看