其實不是真的創建了批量任務,而是用python創建一個文本文件,每行一個要下載的鏈接,然后打開迅雷,復制文本文件的內容,迅雷監測到剪切板變化,彈出下載全部鏈接的對話框~~
實際情況是這樣的,因為用python分析網頁非常,比如下載某頁中的全部pdf鏈接
from __future__ import unicode_literalsfrom bs import BeautifulSoupimport requestsimport codecsr = requests.get('you url')s = BeautifulSoup(r.text)links = s.findall('a')pdfs = []for link in links:href = link.get('href')if href.endswith('.pdf'):pdfs.append(href)with open('you file', 'w', 'gb') as f:for pdf in pdfs:f.write(pdf + '/r/n')
使用python創建多個文件
#coding=utf-8'''Created on 2012-5-29@author: xiaochou'''import osimport timedef nsfile(s):'''The number of new expected documents'''#判斷文件夾是否存在,如果不存在則創建b = os.path.exists("E://testFile//")if b:print "File Exist!"else:os.mkdir("E://testFile//")#生成文件for i in range(1,s+1):localTime = time.strftime("%Y%m%d%H%M%S",time.localtime())#print localtimefilename = "E://testFile//"+localTime+".txt"#a:以追加模式打開(必要時可以創建)append;b:表示二進制f = open(filename,'ab')testnote = '測試文件'f.write(testnote)f.close()#輸出第幾個文件和對應的文件名稱print "file"+" "+str(i)+":"+str(localTime)+".txt"time.sleep(1)print "ALL Down"time.sleep(1)if __name__ == '__main__':s = input("請輸入需要生成的文件數:")nsfile(s)
以上內容是小編給大家分享的Python批量創建迅雷任務及創建多個文件的實例代碼,希望對大家有所幫助。