1. 程式人生 > >Python 下載網路檔案

Python 下載網路檔案

# -*- coding: utf-8 -*-
import requests
import csv
#下載檔案
def downloadfiles(url,count):
	f = requests.get(url)
	filename = str(count)+".pdf"
	with open(filename,"wb") as code:
		code.write(f.content)
#從csv讀取內容
def readfile(path):
	with open(path,'r',encoding='utf-8') as csvfile:
		read = csv.reader(csvfile)
		i=0
		for one in read:
			downloadfiles(one[0],i)
			i = i+1
			print(one[0])
readfile("d:\\baoxian_pdf.csv")