仅作参考
方法1
import time
import datetime
from scrapy import cmdline
def doing():
# 把爬虫程序放在这个类里 sik是爬虫的name
cmdline.execute('scrapy crawl sik'.split())
# h想几时更新,定时到m几分
def time_where(h=8, m=50):
while True:
nows = datetime.datetime.now()
if nows.hour == h and nows.minute == m:
doing()
# 每隔60秒检测一次
time.sleep(60)
time_where()
方法2
import time
import os
while True:
newtime = time.strftime("%H:%M:%S", time.localtime())
if newtime in ['08:00:00', '10:00:00', '12:00:00', '14:00:00', '16:00:00', '18:00:00']:
os.system("scrapy crawl fk")
print('任务执行已完成')
本文介绍了两种使用Python实现定时启动Scrapy爬虫的方法。一种是通过不断检查当前时间是否达到预设时间来启动爬虫;另一种则是在特定时刻执行爬虫任务。这两种方法为自动化抓取网页提供了便利。


被折叠的 条评论
为什么被折叠?



