简体   繁体   English

如何让python代码一遍又一遍地运行?

[英]How can I get a python code to run over and over again?

I have a scraper that scrapes data from a website, then saves the data in .csv files.我有一个从网站上抓取数据的刮刀,然后将数据保存在 .csv 文件中。 What I am looking for is a way to run this code every 10 minutes, without using a loop.我正在寻找的是一种每 10 分钟运行一次此代码而不使用循环的方法。 I have very little knowledge on how to do this.我对如何做到这一点知之甚少。 What approach would you use?你会使用什么方法?

It's impossible to repeat a code without a loop.没有循环就不可能重复代码。

I can only think that you want something like Task Scheluding on Windows ( https://msdn.microsoft.com/pt-br/library/windows/desktop/aa383614.aspx ) or crontab/timers on Linux.我只能认为你想要 Windows 上的 Task Scheluding ( https://msdn.microsoft.com/pt-br/library/windows/desktop/aa383614.aspx ) 或 Linux 上的 crontab/timers 。

Are you using windows or a unix based system?您使用的是 Windows 还是基于 Unix 的系统?

If you're using UNIX, you can schedule jobs to take place at regular intervals with CRON.如果您使用的是 UNIX,则可以使用 CRON 安排作业定期执行。

Execute the following in a terminal window:在终端窗口中执行以下操作:

#edit crontab
crontab -e

Then add the required file you want to execute prefaced by the following CRON instructions:然后添加要执行的所需文件,并以以下 CRON 指令开头:

*/6 * * * * /path/to/desired/Python_version /path/to/executable/file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM