scrapy定时执行抓取任务
在ubuntu环境下,使用scrapy定时执行抓取任务,由于scrapy本身没有提供定时执行的功能,所以采用了crontab的方式进行定时执行:
首先编写要执行的命令脚本cron.sh
#! /bin/sh export PATH=$PATH:/usr/local/bin cd /home/zhangchao/CVS/testCron nohup scrapy crawl example >> example.log 2>&1 &
执行,crontab -e,规定crontab要执行的命令和要执行的时间频率,这里我需要每一分钟就执行scrapy crawl example这条爬取命令:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command */1 * * * * sh /home/zhangchao/CVS/testCron/cron.sh
编辑好了后,发现ubuntu的/var/log/下面没有crontab的日志,原因是因为ubuntu默认没有开启crontab的日志功能,执行如下操作:
emacs /etc/rsyslog.d/50-default.conf ,将cron.*这一行前的注释打开:

然后重启sudo service rsyslog restart
最后就可以使用tail –f /var/log/cron.log查看crontab的日志了,可以看到cron.sh每一分钟被执行了一次:

借此机会复习下,crontab的常见格式:
每分钟执行 */1 * * * *
每小时执行 0 * * * *
每天执行 0 0 * * *
每周执行 0 0 * * 0
每月执行 0 0 1 * *
每年执行 0 0 1 1 *

scrapy定时执行抓取任务的更多相关文章
- Scrapy定时执行爬取任务与定时关闭任务
当我们利用Python scrapy框架写完脚本后,脚本已经可以稳定的进行数据的爬取,但是每次需要手动的执行,太麻烦,如果能自动运行,在自动关闭那就好了,经过小编研究,完全是可以实现的,今天小编介绍2 ...
- SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享
SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享 第一步建库和建表 USE [master] GO CREATE DATABASE [MonitorElapsedHighSQL] G ...
- [转]使用scrapy进行大规模抓取
原文:http://www.yakergong.net/blog/archives/500 使用scrapy有大概半年了,算是有些经验吧,在这里跟大家讨论一下使用scrapy作为爬虫进行大规模抓取可能 ...
- SQL Server定时自动抓取耗时SQL并归档数据脚本分享
原文:SQL Server定时自动抓取耗时SQL并归档数据脚本分享 SQL Server定时自动抓取耗时SQL并归档数据脚本分享 第一步建库 USE [master] GO CREATE DATABA ...
- 在Scrapy项目【内外】使用scrapy shell命令抓取 某网站首页的初步情况
Windows 10家庭中文版,Python 3.6.3,Scrapy 1.5.0, 时隔一月,再次玩Scrapy项目,希望这次可以玩的更进一步. 本文展示使用在 Scrapy项目内.项目外scrap ...
- scrapy实现全站抓取数据
1. scrapy.CrawlSpider scrapy框架提供了多种类型的spider,大致分为两类,一类为基本spider(scrapy.Spider),另一类为通用spider(scrapy.s ...
- Python爬虫【四】Scrapy+Cookies池抓取新浪微博
1.设置ROBOTSTXT_OBEY,由true变为false 2.设置DEFAULT_REQUEST_HEADERS,将其改为request headers 3.根据请求链接,发出第一个请求,设置一 ...
- Scrapy爬虫:抓取大量斗图网站最新表情图片
一:目标 第一次使用Scrapy框架遇到很多坑,坚持去搜索,修改代码就可以解决问题.这次爬取的是一个斗图网站的最新表情图片www.doutula.com/photo/list,练习使用Scrapy ...
- scrapy结合selenium抓取武汉市环保局空气质量日报
1.前言 目标网站:武汉市环境保护局(http://hbj.wuhan.gov.cn/viewAirDarlyForestWaterInfo.jspx).scrapy对接selenium模块抓取空气质 ...
随机推荐
- 〖Linux〗gun screen 配置文件
screen 默认使用 bash shell,一般情况下screen只用于android build,tmux则是我的日常使用多终端管理工具. # Default Shell shell " ...
- 【Linux】shell数组
一.概念 shell数组就是一个元素集合,它把有限个元素用一个名字来命名,然后用编号对他们分区.这个名字称为数组名,用于区分不同内容的编号称为数组的下标. 二.shell数组的定义与增删改查 1.sh ...
- txt文件匹配脚本
# -*- coding:utf-8 -*- import time start = time.clock() data=open("Data.txt","r" ...
- python之模块配置文件ConfigParser(在python3中变化较大)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之模块ConfigParser(在python3中为configparser) #特别注意:py ...
- RHEL7-Samba共享测试
Linux<----->windows之间共享 Samba使用2个进程 smb ip之间的通信用smb (tcp) nmb 主机名之间的通信用nmb (netbi ...
- RHEL SHELL快捷键
Shell快捷键 CTRL+a 调到命令行头 e 调到命令行尾 CTRL+u 光标前面的删除 k 光标后面的删除 CTRL+→词的头 词的尾 ESC+. 粘贴上个命令的尾词 杀掉远 ...
- rtl-sdr在win7和ubuntu16.04的安装
硬件准备 RTL2832+R820T2 usb dongle x 1 Long wire antenna x 1 USB电视棒的购买: 在淘宝上搜索"软件无线电"或"rt ...
- Android 代码画角标 offcutView
效果如下: 代码: <com.andye.OffcutView android:layout_width="30dp" android:layout_h ...
- open()系统调用的实现
open系统调用的服务例程是sys_open()函数,它接受三个参数:要打开文件的路径名filename, 访问模式的表示flags和文件权限掩码mode.在内核中,sys_open实际调用do_sy ...
- NoSQL生态系统(nosql ecosystem)
Unlike most of the other projects in this book, NoSQL is not a tool, but an ecosystem composed of se ...