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

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

相关文章

Python制作exe文件简单流程

Python制作exe文件简单流程

一:什么是exe? exe是Windows环境中的文件扩展名之一,它是一个可执行文件,虽然扩展程序在一般情况下是隐藏的,但是我们可以通过取消选中资源管理器文件夹的高级设置中的“不显示已注...

Python设计模式之模板方法模式实例详解

Python设计模式之模板方法模式实例详解

本文实例讲述了Python设计模式之模板方法模式。分享给大家供大家参考,具体如下: 模板方法模式(Template Method Pattern):定义一个操作中的算法骨架,将一些步骤延...

python使用matplotlib绘制折线图教程

python使用matplotlib绘制折线图教程

matplotlib简介 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图。而且也可以方便地将它作为绘图控件,嵌入...

Python中格式化format()方法详解

 Python中格式化format()方法详解 Python中格式化输出字符串使用format()函数, 字符串即类, 可以使用方法; Python是完全面向对象的语言, 任...

pandas 读取各种格式文件的方法

pandas 读取各种格式文件: 前置工序: import pandas as pd csv 文件读取中文错误处理: utf-8 codec can't decode .... pd...