Skip to content
Advertisement

Save Images with orginal name

I have script to download images from website. But it’s saves name with ‘images1, images2, images3, images4 etc’

I need to save images with orginal name. If the images name 43343.jpg i need to save with 43343.jpg I use beautifulsoup and requests for this case.

Sorry my english. It’s not my first language

JavaScript

Advertisement

Answer

Try replacing this part of your code

JavaScript

with this:

JavaScript

This will get the last element of your image_path (after the last slash), which should be the name of the image, given the rest of your code is correct and I understood the works of it correctly.

Also, I don’t know what your image_link variable looks like but maybe you need to replace the / with \ if your path uses backslashes.


On a last note, consider putting a bit more effort into your stackoverflow questions or your code quality in general. The sheer amount of empty lines makes the code really tedious to read and all the nesting (going deeper and deeper with try-except clauses) certainly doesn’t help with that either.

Aside from that, there are lots of better ways to achieve your intended functionality without multiple bare except clauses. In fact, you should never use a bare except statement (`except:` without an exception classname after it). But that’s a story for another time.
Advertisement