Ben G
Ben G

Reputation: 11

How to loop two variables through a string for websites

I'd like to loop two variables for this URL.

If it was VBA I would run the for a = 1 to 5 and then embed the for i = 1 to 9 but I can't work out how to do this in python. I can use one variable fine but not the two together.

The current script is below.

for a, i in zip(range(1,6),range(1, 10)):

    url = ("https://dlh.apricot.com/cfs/ntr/watchItem/CD_R20040140%s0%s" % a % i)

Upvotes: 0

Views: 101

Answers (1)

Floh
Floh

Reputation: 909

Here you can do it really straightforward by two nested for:

for first_id in range(1,6):
    for second_id in range(1,10):
        url = f"https://dlh.apricot.com/cfs/ntr/watchItem/CD_R20040140{first_id}0{second_id}"
        do_stuff(url)

Upvotes: 1

Related Questions