Home python download pictures on the URL links in the TXT file

download pictures on the URL links in the TXT file




There is a TXT file with links to sites with images, each starts with a new row. How best to walk on them to substitute every one of them in URLLIB, in order to keep pictures on PC.

Example TXT file:

// A / B / img.jpg

I will substitute a link here.

urllib.request.urlretrieve (src, "img" + str (i) + ".jpg")

Answer 1

To take the information that is in your .txt file, there is a command that goes out of the box, Open () .

In your case, it should look something like this:

file = open ("yourfile.txt", "r")
For Line in File:
  # Line is one line from a text document
  # i.e. Link to your image. You can make Print (Line) to verify
  urllib.request.urlretrieve (SRC, "img" + str (Line) + ".jpg")
Previous articleATOI Sales
Next articlehow to make ar on unity 2019 +

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions