Python批量创建迅雷任务及创建多个文件
其实不是真的创建了批量任务,而是用python创建一个文本文件,每行一个要下载的链接,然后打开迅雷,复制文本文件的内容,迅雷监测到剪切板变化,弹出下载全部链接的对话框~~
实际情况是这样的,因为用python分析网页非常,比如下载某页中的全部pdf链接
from__future__importunicode_literals
frombsimportBeautifulSoup
importrequests
importcodecs
r=requests.get('youurl')
s=BeautifulSoup(r.text)
links=s.findall('a')
pdfs=[]
forlinkinlinks:
href=link.get('href')
ifhref.endswith('.pdf'):
pdfs.append(href)
withopen('youfile','w','gb')asf:
forpdfinpdfs:
f.write(pdf+'\r\n')
使用python创建多个文件
#coding=utf-8
'''
Createdon2012-5-29
@author:xiaochou
'''
importos
importtime
defnsfile(s):
'''Thenumberofnewexpecteddocuments'''
#判断文件夹是否存在,如果不存在则创建
b=os.path.exists("E:\\testFile\\")
ifb:
print"FileExist!"
else:
os.mkdir("E:\\testFile\\")
#生成文件
foriinrange(1,s+1):
localTime=time.strftime("%Y%m%d%H%M%S",time.localtime())
#printlocaltime
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"ALLDown"
time.sleep(1)
if__name__=='__main__':
s=input("请输入需要生成的文件数:")
nsfile(s)
以上内容是小编给大家分享的Python批量创建迅雷任务及创建多个文件的实例代码,希望对大家有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下