【发布时间】:2023-07-23 11:25:04
【问题描述】:
我是 Python 的初学者。我有一个需要始终执行的 python 脚本。该脚本从数据库中获取一些 url 并调用一些函数来检查链接的活动。这些函数应该针对每个 url 以特定的时间间隔执行(每个 url 的特定值,并且在检索 url 时从 db 中获取)。我阅读了有关 sched 模块和 cron 选项卡的信息,但对使用什么以及如何使用它们来实现所有这些感到有些困惑!或者是否有更好的解决方案来实现这一切? 1) 始终运行脚本 2)在每个 url 的代码中,调用/检查方法的间隔是不同的,每个应该在其特定的时间间隔内检查 我的主要代码将类似于
def checkSublinks(urlId,search,domain,depth_restricted_to,links_restricted_to):
#method here
try:
db=MySQLdb.connect("localhost","root","password","crawler")
cursor=db.cursor();
query="select * from website"
cursor.execute(query)
result=cursor.fetchall()
for row in result:
depth=0
maxCountReached=False
urlId=row[0]
print "Id :",urlId
search=row[1]
domain=row[2]
depth_restricted_to=row[3]
links_restricted_to=row[4]
website_uptime=row[5]
link_uptime=row[6]
checkSublinks(urlId,search,domain,depth_restricted_to,links_restricted_to)
except Exception,e:
print e
print "Error in creating DB Connection!"
finally:
db.close()
这里每个 url 都在其相应的时间间隔内调用 checkSublinks。尽早在此提出您宝贵的建议
【问题讨论】:
标签: python scheduled-tasks schedule