其實不是真的創建了批量任務,而是用python創建一個文本文件,每行一個要下載的鏈接,然后打開迅雷,復制文本文件的內容,迅雷監測到剪切板變化,彈出下載全部鏈接的對話框~~
實際情況是這樣的,因為用python分析網頁非常,比如下載某頁中的全部pdf鏈接
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
from __future__ import unicode_literals from bs import BeautifulSoup import requests import codecs r = 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創建多個文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#coding=utf-8 ''' Created on 2012-5-29 @author: xiaochou ''' import os import time def 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 localtime filename = "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批量創建迅雷任務及創建多個文件的實例代碼,希望對大家有所幫助。