1

我正在尝试编写一个简单的程序来一遍又一遍地在 youtube 中打开一个 3 分钟的视频,并在特定数量的页面后关闭每个浏览器然后重新开始但它只运行一次.. 请建议

#Keep playing a youtube clip

import time , webbrowser , os


total_breaks = -1
start=0
def Play():
    try:
        while start != total_breaks:
            print("The {} Play of WaKra Movie started at ".format(start+1),time.ctime())

            with webbrowser.open("https://www.youtube.com/watch?v=XXXXXXXXXX") as play:
                time.sleep(5) #*60*60)
                global start
                start = start + 1
                #time.sleep(5)
                if start % 5 == 0: #every 5 pages close all browsers 
                    os.popen('TASKKILL /IM  iexplore.exe /f')
                    os.popen('TASKKILL /IM firefox.exe /f ')
                    os.popen('TASKKILL /IM chrome.exe /f ')
    except:
        print ("Some Browsers were not found")  

    print("Program terminated at",time.ctime())





Play()
4

1 回答 1

1

一个快速的解决方法是:

#Keep playing a youtube clip

import time , webbrowser , os


total_breaks = -1
start=0
def play():
    try:
        while start != total_breaks:
            print("The {} Play of WaKra Movie started at ".format(start+1),time.ctime())

            with webbrowser.open("https://www.youtube.com/watch?v=XXXXXXXXXX") as play:
                time.sleep(5) #*60*60)
                global start
                start = start + 1
                #time.sleep(5)
                if start % 5 == 0: #every 5 pages close all browsers 
                    os.popen('TASKKILL /IM  iexplore.exe /f')
                    os.popen('TASKKILL /IM firefox.exe /f ')
                    os.popen('TASKKILL /IM chrome.exe /f ')
    except:
        print ("Some Browsers were not found")  

    print("Program terminated at",time.ctime())




while True:
    play()
    time.sleep(180)

我不太确定你的程序的目的是什么,但这将play每 3 分钟执行一次你的函数(顺便说一句,函数总是小写)。

于 2015-05-07T09:28:09.677 回答