当前位置:Gxlcms > Python > Python批量创建迅雷任务及创建多个文件

Python批量创建迅雷任务及创建多个文件

时间:2021-07-01 10:21:17 帮助过:56人阅读

其实不是真的创建了批量任务,而是用python创建一个文本文件,每行一个要下载的链接,然后打开迅雷,复制文本文件的内容,迅雷监测到剪切板变化,弹出下载全部链接的对话框~~

实际情况是这样的,因为用python分析网页非常,比如下载某页中的全部pdf链接

  1. from __future__ import unicode_literals
  2. from bs import BeautifulSoup
  3. import requests
  4. import codecs
  5. r = requests.get('you url')
  6. s = BeautifulSoup(r.text)
  7. links = s.findall('a')
  8. pdfs = []
  9. for link in links:
  10. href = link.get('href')
  11. if href.endswith('.pdf'):
  12. pdfs.append(href)
  13. with open('you file', 'w', 'gb') as f:
  14. for pdf in pdfs:
  15. f.write(pdf + '\r\n')

使用python创建多个文件

  1. #coding=utf-8
  2. '''
  3. Created on 2012-5-29
  4. @author: xiaochou
  5. '''
  6. import os
  7. import time
  8. def nsfile(s):
  9. '''The number of new expected documents'''
  10. #判断文件夹是否存在,如果不存在则创建
  11. b = os.path.exists("E:\\testFile\\")
  12. if b:
  13. print "File Exist!"
  14. else:
  15. os.mkdir("E:\\testFile\\")
  16. #生成文件
  17. for i in range(1,s+1):
  18. localTime = time.strftime("%Y%m%d%H%M%S",time.localtime())
  19. #print localtime
  20. filename = "E:\\testFile\\"+localTime+".txt"
  21. #a:以追加模式打开(必要时可以创建)append;b:表示二进制
  22. f = open(filename,'ab')
  23. testnote = '测试文件'
  24. f.write(testnote)
  25. f.close()
  26. #
输出第几个文件和对应的文件名称 print "file"+" "+str(i)+":"+str(localTime)+".txt" time.sleep(1) print "ALL Down" time.sleep(1) if __name__ == '__main__': s = input("请输入需要生成的文件数:") nsfile(s)

以上内容是小编给大家分享的Python批量创建迅雷任务及创建多个文件的实例代码,希望对大家有所帮助。

人气教程排行