python 自動下載實現(1)


迅雷下載和excel都能實現了,合並代碼

index.py

import openpyxl
import urllib.request
import time
import os
import re

filePath = "F:/download/" 
#換成自己的下載目錄地址
wb = openpyxl.load_workbook('file/allhref.xlsx')
#換成自己的exal目錄

sheets = wb.sheetnames
# print(sheets, type(sheets)) 
import dowloadXunlei


def getHref(ws):
    # print(ws['A']) A一豎列
    #循環B數列
    i = 0
    for href in  ws['B']: 
        name = (ws['A'][i].value)
        i = i + 1
        if href.value != 'href': 
             getFileType(href.value, name)
        

def getFileType(url, name): 
    if(re.search("jpg",url)):
        dowloadPic(url, name)
    elif(re.search("rmvb",url)):
       dowloadXunlei.download(url, name)
    elif(re.search("mkv",url)):
       dowloadXunlei.download(url, name) 
    elif(re.search("mp4",url)):
       dowloadXunlei.download(url, name) 

         
def dowloadPic(url, fileName):
        response = urllib.request.urlopen(url)
        data = response.read()
        t = int(time.time() * 1000)
        os.mkdir("download/"+fileName)
        name = filePath +fileName+"/"+ '%d'%t+".jpg"
        print(name)
        with open(name, 'wb') as code:
            code.write(data)
            print('finish')


for sheet in sheets:        # 循環表
   if(sheet == 'Sheet1'): getHref(wb[sheet])
        # wb[sheet]

引入迅雷下載的py

dowloadXunlei.py
import os
import time

save_path = "C:/迅雷下載的目錄" 

def download(url,name):
    downloadFile(url)

def get_filename(url):
    return os.path.split(url)[1]

def check_start(filename):
    cache_file = filename+".xltd"
    return os.path.exists(os.path.join(save_path,cache_file))

def check_end(fiename):
    return os.path.exists(os.path.join(save_path,fiename))

def downloadFile(downUrl): 
    fileNames = get_filename(downUrl)
    isFinish = not check_end(fileNames)
    isExist = not check_start(fileNames)
    
    if(isExist):
        #如果這個任務不存在
        print('開始')
        #迅雷exe的目錄地址
        os.system("\"D:\Program\\Thunder.exe\" -StartType:DesktopIcon %s"%downUrl)
    else:
        if(isFinish):
            print('繼續')

 

python index.py就能實現文本的下載了

 

 excel目錄

還要實現

1.自動獲取電影和電視劇的名稱,保存到fileName欄,

2.和對text,pdf的下載支持實現

3.獲取開始下載時間並且保存到startTime

4.下載結束,監聽文件的狀態,下載完成記錄overTime的時間

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM