脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python 每天如何定时启动爬虫任务(实现方法分享)

python 每天如何定时启动爬虫任务(实现方法分享)

2021-02-22 00:32大蛇王 Python

python 每天如何定时启动爬虫任务?今天小编就为大家分享一篇python 实现每天定时启动爬虫任务的方法。具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

python2.7环境下运行

安装相关模块

想要每天定时启动,最好是把程序放在linux服务器上运行,毕竟linux可以不用关机,即定时任务一直存活;

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#coding:utf8
import datetime
import time
def doSth():
 # 把爬虫程序放在这个类里
 print(u'这个程序要开始疯狂的运转啦')
# 一般网站都是1:00点更新数据,所以每天凌晨一点启动
def main(h=1,m=0):
 while True:
  now = datetime.datetime.now()
  # print(now.hour, now.minute)
  if now.hour == h and now.minute == m:
   break
  # 每隔60秒检测一次
  time.sleep(60)
 doSth()
main()

以上这篇python 每天如何定时启动爬虫任务(实现方法分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/t8116189520/article/details/78832548

延伸 · 阅读

精彩推荐