I have a script to download the files from a file full of links(one link per line). To do the same, I made a for loop which would download every link in each line, but unexpectedly it's only downloading the last link in the file. Here is my code for the python script that I tried:
import time
import requests
import requests
import os.path
with open('Links.txt', 'r', encoding='utf-8') as link_file:
for link in link_file:
def download_url(_url):
print("downloading: ", _url)
file_name_start_pos = _url.rfind("/") + 1
file_name = _url[file_name_start_pos:]
r = requests.get(_url, stream=True)
if r.status_code == requests.codes.ok:
with open(file_name, 'wb') as f:
for data in r:
f.write(data)
return os.path.exists(file_name)
download_url(link)
Please help with my script, any alternatives would be fine as well.