其实不是真的创建了批量任务,而是用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 + '')
登录后复制
使用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批量创建迅雷任务及创建多个文件的实例代码,希望对大家有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2535637.html