Created
January 4, 2019 13:02
-
-
Save BeFiveINFO/1dfd03e56708177a58a4f7d8997fc325 to your computer and use it in GitHub Desktop.
[Python3] Batch Download Files by URLs Listed in a Text File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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