racpider

一个使用web服务器来进行分布式的爬虫框架

核心思想如下:

racpider

使用Redis来进行缓存队列,当有slaver发送pull请求时,redis出队列,分配一个url到slaver

slaver进行爬虫工作,将数据采用mongodb存储在本地硬盘上,并且返回新的一轮url(此处使用requests包进行http发送请求)

新的url将会push到服务器端,此时服务器端使用bloomfilter来进行重复url过滤,将不重复的url加入到redis队列中,重复此过程直至redis队列为空。

后续分析时,从slaver中逐个读取mongodb中相应数据库的collection进行分析汇总。

重写src/analy/script.py中的filter方法,将url符合提取要求的函数筛选出来

重写src/analy/script.py中的parse方法,parse方法的函数参数为body,使用bs4等进行解析或者存储

getting start

#服务器端
./src/monitor.py

#client端
./src/slaver.py

enhance

delay

todo

bugs

questions

Server

slave

changelog

5月9日

5月14日

client dependence

server dependence

5月24日

配置文件在Racpider.json

{
    "seeds":["http://news.qq.com/"], //为要抓取的种子
    "regexp":"qq.com", //抓取域名的匹配正则
    "name":"qq_news", // 爬虫名称
    "redis":{  //redis配置
        "host":"127.0.0.1",
        "port":"6379",
        "db":"0"
    },
    "mongodb":{ //客户端mongodb配置
        "host":"127.0.0.1",
        "port":"20132",
        "name":"racpider"
        },
    "server":{ // web服务器配置,用来实现分布式
        "host":"192.168.31.110",
        "port":"5237",
        "debug":"False"
    },
    "auth":{ //【todo】认证
        "username":"username",
        "password":"password"
    },
    "timeout":"2",//超时时间
    "sleep":"1", //每次抓取空当时间
    "clients":[ //供master来进行分析
        {
            "host":"10.211.55.5",
            "port":"20132"
        },
        {
            "host":"10.211.55.7",
            "port":"20132"
        }
    ]
}

LISCENSE

The MIT License (MIT)

Copyright (c) 2015 Xiaodong Cun

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.