项目作者: nciefeiniu

项目描述 :
基于scrapy-redis scrapy-splash的通用爬虫(包括ajax请求的数据)
高级语言: Python
项目地址: git://github.com/nciefeiniu/totalstsation_scrapy.git


网站通用爬虫 scrapy-splash and scrapy-redis

scrapy redis splash高度结合

主要框架:

  • scrapy
  • scrapy-splash
  • scrapy-redis

splash 可以采用负载均衡,多节点部署。

scrapy 爬虫也需要多节点部署。单机全站爬取太慢。


splash 安装

安装教程 官方文档


数据表结构

表结构在项目下的models.py中

  1. python3 models.py

测试环境下的分布式splash

宿主机安装 nginx

  1. apt install nginx -y
  2. # or
  3. yum install nginx -y

启动splash 容器

  1. sudo ./create_splash.sh

修改 nginx 的配置文件(/etc/nginx/nginx.conf),在 http 中增加

  1. upstream splash {
  2. least_conn;
  3. server 127.0.0.1:8051;
  4. server 127.0.0.1:8052;
  5. server 127.0.0.1:8053;
  6. server 127.0.0.1:8054;
  7. server 127.0.0.1:8055;
  8. }
  9. server {
  10. listen 8050;
  11. location / {
  12. proxy_pass http://splash;
  13. proxy_connect_timeout 300;
  14. proxy_read_timeout 400;
  15. }
  16. }

重新加载 nginx 配置文件

  1. nginx -s reload

测试环境下docker启动爬虫

  1. git clone http://git.epmap.org/tao.liu/totalstation_spider.git
  2. cd totalstation_spider

请修改 .env_sample 文件

  1. # 编译镜像
  2. docker build -t totalspider:v1 .
  3. # 启动docker容器
  4. docker run -itd --name xxx totalspider:v1

然后向redis 中添加代爬取的网站,

  1. # 连接redis
  2. redis-cli -h xx.xx.xx.xx -p xxxx
  3. # 向redis中添加数据
  4. lpush waiting_for_crawl:start_urls http://www.gov.cn

爬虫已经开始全站爬取。

TODO

  • 网页返回数据去重复
  • 网页相似度检测
  • 监测网页更新