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

yipeiwu_com5年前Python基础

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

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

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创建多个文件

#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批量创建迅雷任务及创建多个文件的实例代码,希望对大家有所帮助。

相关文章

Gauss-Seidel迭代算法的Python实现详解

import numpy as np import time 1.1 Gauss-Seidel迭代算法 def GaussSeidel_tensor_V2(A,b,Delta,...

Python 编码规范(Google Python Style Guide)

Python 风格规范(Google) 本项目并非 Google 官方项目, 而是由国内程序员凭热情创建和维护。 如果你关注的是 Google 官方英文版, 请移步 Googl...

python中随机函数random用法实例

本文实例讲述了python中随机函数random用法。分享给大家供大家参考。具体如下: python中的random模块功能非常强大,可以生成各种随机值 #! python # ra...

Python中列表、字典、元组、集合数据结构整理

本文详细归纳整理了Python中列表、字典、元组、集合数据结构。分享给大家供大家参考。具体分析如下: 列表:复制代码 代码如下:shoplist = ['apple', 'mango',...

python opencv之SURF算法示例

python opencv之SURF算法示例

本文介绍了python opencv之SURF算法示例,分享给大家,具体如下: 目标: SURF算法基础 opencv总SURF算法的使用 原理: 上节课使用了SIFT算法,...