How can I use a for loop to modify a variable inside a string while I download a list of images using BS?

leoro

I am using BeautifulSoup to scrape a page with a table. When I am going to download some images inside that table using a for loop and "urlretrieve", I am not able to give each image a different name, thus the each time an image is downloaded, it is replaced by a new image because they have the same name.

In other words, I am not able to change a variable inside a string so that I can give each downloaded image a different name.

enter image description here

enter image description here

enter image description here

Untitled123

From your last picture, you are setting num to 0 at each loop iteration. You want to take it out of the loop.

for ...
  num=0

to

num = 0
for ...
  num += 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

for loops in Python - how to modify i inside the loop

How can I use fetch in while loop

C# How do I use a variable outside of a loop that changes from string to int inside the loop?

How can I pull multiple rows from containers while using a loop for multiple containers in BS4?

How can I get Calendar Button's value using its key inside the while loop, PySimpleGUI?

How can I sum up a list of numbers inside a variable which I generated inside a forEach loop

How can I enter the elements of my list into a string with a use of loop?

How can I use a loop inside a command?

how can I make an for-loop work with a variable inside a variable

How can I return to a line inside my While loop

How can i use a while loop on this program?

How can I use a FOREACH loop inside of a WHILE loop to create several columns

How can I use loop variable in array?

For loop, how can i use loop variable outside loop

PHP - How can I nest a while loop inside an if isset condition?

Angular: How can I access and modify an item inside a scope list?

How can I input an if statement inside a while loop?

How can i use dynamically generated string inside `list() = $variable`?

How can i download many images async using WebClient?

How can I check if a variable is inside a list during a for loop in robot framework?

How do I Store an Array Variable Inside of Another Array Variable using while loop and for each?

How do I update a "global" variable inside a while loop?

How can I use this for loop variable in django?

Can I use a variable to determine a string in a list?

How can I use <bind> within a loop while using MyBatis?

PHP/MYSQLI how can I return a variable from a while loop inside a form to use in a $_GET request in that form's action/method?

How can I modify a variable in a list comprehension?

How can I use a string variable in .bat for-loop?

how can i convert a string to a list to index using a for loop in lua?