How to open different web pages using the while

0

I would like the program to execute a command three times: wait 10 seconds to open a web page. For this to occur, set the following code:

import time
import webbrowser

total_breaks = 3
break_count = 0

while(break_count < total_breaks):
    time.sleep(10)
    webbrowser.open("https://www.youtube.com/watch?v=zywDiFdxopU")
    webbrowser.open("https://www.youtube.com/watch?v=QwOU3bnuU0k")
    webbrowser.open("https://www.youtube.com/watch?v=b2WzocbSd2w")
    break_count = break_count + 1

But it turns out that the pages are opened at the same time. I would like the first time he opens the page a and the second time he opens the page b and the third time he opens the page c. How do I instead of opening the program to all web pages, it opens a page each time the program is run?

    
asked by anonymous 26.09.2017 / 21:11

1 answer

1

For each open has a corresponding sleep . This already gives you a clue that your loop can not be made up of several open the way it is, but only one.

Since you will only have a open , you need to vary its parameter. As the possible parameters are fixed, we'll put them in a tuple and iterate over it with a for instead of a while :

import time
import webbrowser

enderecos = ("https://www.youtube.com/watch?v=zywDiFdxopU", "https://www.youtube.com/watch?v=QwOU3bnuU0k", "https://www.youtube.com/watch?v=b2WzocbSd2w");

for endereco in enderecos:
  webbrowser.open(endereco)
  time.sleep(10)
    
26.09.2017 / 21:20