Skip to content
Advertisement

How to change names of scraped images with Python?

So I need to download the images of every coin on the list on CoinGecko, so I wrote the following code:

JavaScript

However, I need to save the images with their names being the same as the ticker of the coin of that list from CoinGecko (rename bitcoin.png?1547033579 to BTC.png, ethereum.png?1595348880 to ETH.png, and so forth). There are over 7000 images that need to be renamed, and many of them have quite unique names, so slicing does not work here.

What is the way to do it?

Advertisement

Answer

I was browsing the html file and I found that the tag you are looking at has an alt parameter that has the ticker on the end of the string.

JavaScript

So we can use that to get the correct name like so:

JavaScript

We are basically extracting the value between the parenthesis using string slicing.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement