28 lines
773 B
Python
28 lines
773 B
Python
|
global urllib
|
||
|
import urllib.request
|
||
|
|
||
|
global download
|
||
|
def download(url,decode = "utf-8"):
|
||
|
request = urllib.request.Request(url,headers={"User-Agent":"Mozilla/5.0"})
|
||
|
response = urllib.request.urlopen(request)
|
||
|
rt = response.read()
|
||
|
if decode == False: return rt
|
||
|
return response.read().decode(decode)
|
||
|
|
||
|
global fileDl
|
||
|
def fileDl(url,file,read = True,decode = "utf-8"):
|
||
|
if os.path.isfile(file):
|
||
|
if read == True:
|
||
|
return readFile(file,decode)
|
||
|
return
|
||
|
|
||
|
#print(url)
|
||
|
data = download(url,False)
|
||
|
fileh = open(tmpFile,"wb")
|
||
|
fileh.write(data)
|
||
|
fileh.close()
|
||
|
if pUp(file) != "" and not os.path.isdir(pUp(file)): os.makedirs(pUp(file))
|
||
|
os.rename(tmpFile,file)
|
||
|
if read == False: return
|
||
|
if decode == False: return data
|
||
|
return data.decode(decode)
|