You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
879 B
30 lines
879 B
import json
|
|
from pathlib import Path
|
|
|
|
import requests
|
|
|
|
from Util import MysqlUtil
|
|
from Util.CommonUtil import printf
|
|
|
|
if __name__ == '__main__':
|
|
basePath = 'D:/TuPian'
|
|
sql = 'select url from t_university_image '
|
|
with open("Config.json", 'r') as load_f:
|
|
connect = json.load(load_f)
|
|
db = MysqlUtil.MySQLConnect(connect)
|
|
s = db.fetchall(sql)
|
|
num = 1
|
|
for x in s:
|
|
url = x['url']
|
|
truePath = basePath + "/" + url.split('/')[-1]
|
|
my_file = Path(truePath)
|
|
if not my_file.exists():
|
|
# 下载
|
|
r = requests.get(url)
|
|
with open(truePath, "wb") as code:
|
|
code.write(r.content)
|
|
printf("成功完下文件:" + truePath)
|
|
printf("成功完成" + str(num) + "个,共" + str(len(s)) + "个!")
|
|
num = num + 1
|
|
db.close()
|