Python &引用;“时间睡眠”;在特定的几天或几周内
需要此代码的帮助,我想机器人打开网站每24小时,但不是在周五和周六 我怎么做Python &引用;“时间睡眠”;在特定的几天或几周内,python,python-3.x,python-2.7,python-requests-html,Python,Python 3.x,Python 2.7,Python Requests Html,需要此代码的帮助,我想机器人打开网站每24小时,但不是在周五和周六 我怎么做 import webbrowser from pynput.mouse import Button, Controller import time print("Hello! Welcome to 1Report Destroyer") time.sleep(2) print("From now, you have nothing to worry about") time.s
import webbrowser
from pynput.mouse import Button, Controller
import time
print("Hello! Welcome to 1Report Destroyer")
time.sleep(2)
print("From now, you have nothing to worry about")
time.sleep(2)
print("LET ME DO YOUR JOB")
while True:
time.sleep(86400)
print("lets Destroy")
webbrowser.open("https://one.prat.idf.il/finish")
mouse = Controller()
print("Current position: " + str(mouse.position))
mouse.position = (949, 555)
print("Current position: " + str(mouse.position))
time.sleep(5)
mouse.click(Button.left, 1)
print("ON YOUR FACE 1REPORT")
使用datetime库
from datetime import datetime
然后在您的while循环中包含一个if语句,如下所示:
if datetime.today().strftime('%A') not in ['Friday', 'Saturday']:
# Query site
或
如果datetime.today().weekday()<4或datetime.today().weekday()>5:
#查询站点
您可以尝试以下方法:
import datetime
from datetime import date
import calendar
today = date.today()
TODAY = today.strftime("%d %m %Y")
def findDay(date):
day, month, year = (int(i) for i in date.split(' '))
day = datetime.date(year, month, day)
return day.strftime("%A")
print(findDay(TODAY))
然后可以运行if语句 如果我想在其他日子的特定时间完成,我该怎么做?
import datetime
from datetime import date
import calendar
today = date.today()
TODAY = today.strftime("%d %m %Y")
def findDay(date):
day, month, year = (int(i) for i in date.split(' '))
day = datetime.date(year, month, day)
return day.strftime("%A")
print(findDay(TODAY))