Skip to content

Instantly share code, notes, and snippets.

@BeFiveINFO
Created January 4, 2019 13:02
Show Gist options
  • Save BeFiveINFO/1dfd03e56708177a58a4f7d8997fc325 to your computer and use it in GitHub Desktop.
Save BeFiveINFO/1dfd03e56708177a58a4f7d8997fc325 to your computer and use it in GitHub Desktop.
[Python3] Batch Download Files by URLs Listed in a Text File
#!/usr/local/bin/python3
#-*- coding:utf-8 -*-
import re
import requests
import os
# Function to parse url in a file one by one into a list
def loadTextFile(filePath):
lines = [line.rstrip('\n') for line in open(filePath)]
return lines
# Change the file name of url list to anything you like
urls = loadTextFile('list.txt')
# loop through the list containing the urls
for url in urls:
req = requests.get(url)
path, fname = os.path.split(url)
path = path.split('/')
print(path[-1],fname)
with open('pdf/'+path[-1]+'-'+fname, "wb") as code:
code.write(req.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment