Python实现115网盘自动下载的方法


Posted in Python onSeptember 30, 2014

本文实例讲述了Python实现115网盘自动下载的方法。分享给大家供大家参考。具体实现方法如下:

实例中的1.txt,是网页http://bbs.pediy.com/showthread.php?t=144788另存为1.txt

通过每3秒钟复制一个下载链接到粘贴板,复制时会自动调用115客户端下载,每下载10个文件会手工输入一个字符,防止一下下载太多,卡死机器

具体代码如下:

import re, os, time
import webbrowser
import urllib
  
if __name__ == "__main__":
  fp = open("c:\\1.txt")
  
  https = re.compile(r"(http://u.*)")
  urlList = []
  for url in https.findall(fp.read()):
    urlList.append(url)
  
  downloadUrlList = []
  IsFirst = 1
  print urlList
  for url in urlList:
    doc = urllib.urlopen(url).read()
    reDownloadUrl = re.compile(r'(http://115.com/file/.*)"')
    for downloadUrl in reDownloadUrl.findall(doc):
      if IsFirst:
        downloadUrlList.append(downloadUrl)
        IsFirst = 0
    IsFirst = 1
    #print "-"*20
  
  for url in downloadUrlList:
    print url
    
  import win32clipboard
  import win32con
  def copyToClipboard(copyText):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(win32con.CF_TEXT, copyText)
    win32clipboard.CloseClipboard()
    
  #downloadUrlList = ["http://115.com/file/cmlirmfo","http://115.com/file/ew7htcjc","http://115.com/file/cm25l95e","http://115.com/file/atn8dsgj","http://115.com/file/b3e0ae5k","http://115.com/file/cm27rs3g","http://115.com/file/cmkwjpa1","http://115.com/file/ew4sx25c","http://115.com/file/d2b1alj8","http://115.com/file/b3c29o48","http://115.com/file/ew8ctkyc","http://115.com/file/b3m4ea70","http://115.com/file/atcph3md","http://115.com/file/ew9fw53a","http://115.com/file/cm512ct1","http://115.com/file/ewx7d35c","http://115.com/file/at8nd5xj","http://115.com/file/ewcs6jbj","http://115.com/file/b3104ve1","http://115.com/file/b3b1koke","http://115.com/file/d2st6pv6","http://115.com/file/atb20b6h","http://115.com/file/b353salz","http://115.com/file/atzilrkp","http://115.com/file/cmg35and","http://115.com/file/cmq5ceje","http://115.com/file/atkdb5oc","http://115.com/file/d297u2v6","http://115.com/file/ataqteic","http://115.com/file/cm7ralmz","http://115.com/file/cm70v4nr","http://115.com/file/cmfhr2so","http://115.com/file/atvtkaja","http://115.com/file/b3t7b6aw","http://115.com/file/atoyp4iz","http://115.com/file/ewpk79kj","http://115.com/file/at5k044x","http://115.com/file/d2mo0678","http://115.com/file/a9hegswp","http://115.com/file/bl472ir1","http://115.com/file/dl2dgqi9","http://115.com/file/dl20ky2a","http://115.com/file/bll2yssk","http://115.com/file/a9jzzlca","http://115.com/file/c4z1ek4d","http://115.com/file/blpk4pv1","http://115.com/file/c4rjotdz","http://115.com/file/a9g43daa","http://115.com/file/efnn38jr","http://115.com/file/c4leomjd","http://115.com/file/dlpw9s6i","http://115.com/file/a9n0jv8x","http://115.com/file/c48savoo","http://115.com/file/ef8og8la","http://115.com/file/a9cjk9lx","http://115.com/file/blo38e31","http://115.com/file/a987cika","http://115.com/file/c4vic87g","http://115.com/file/bl5l0syx","http://115.com/file/c4gdl7ne","http://115.com/file/efym0xhy","http://115.com/file/dl88b43f","http://115.com/file/bw4wfxa1","http://115.com/file/eswz3bgj","http://115.com/file/czw0b3g2","http://115.com/file/dis9mjcx","http://115.com/file/ajzrgiyz","http://115.com/file/es5o43lz","http://115.com/file/dnasw0kp","http://115.com/file/dnagnndx","http://115.com/file/clwr2xxg","http://115.com/file/bhbcnnwe","http://115.com/file/aq2rp9ga","http://115.com/file/e601turs","http://115.com/file/dn46qs7x","http://115.com/file/clwonrwg","http://115.com/file/dn43i7jf","http://115.com/file/bhbgrnfz","http://115.com/file/dnsl0kxp"]
  i = 0
  while i<100:
    if len(downloadUrlList) == 0:
      break
    copyToClipboard(downloadUrlList.pop())
    time.sleep(3)
    i = i + 1
    if i % 10 == 0:
      os.system("pause")
  
  print "after pause"

希望本文所述对大家的Python程序设计有所帮助.

Python 相关文章推荐
Python StringIO模块实现在内存缓冲区中读写数据
Apr 08 Python
简单介绍Python中的floor()方法
May 15 Python
python下setuptools的安装详解及No module named setuptools的解决方法
Jul 06 Python
python数据结构之线性表的顺序存储结构
Sep 28 Python
python 2.7 检测一个网页是否能正常访问的方法
Dec 26 Python
python利用Tesseract识别验证码的方法示例
Jan 21 Python
解决Python3 被PHP程序调用执行返回乱码的问题
Feb 16 Python
Flask框架中request、请求钩子、上下文用法分析
Jul 23 Python
Python实现密钥密码(加解密)实例详解
Apr 26 Python
python redis存入字典序列化存储教程
Jul 16 Python
pandas针对excel处理的实现
Jan 15 Python
Python数据分析入门之数据读取与存储
May 13 Python
python打开网页和暂停实例
Sep 30 #Python
Python解析网页源代码中的115网盘链接实例
Sep 30 #Python
python网络编程之读取网站根目录实例
Sep 30 #Python
python中sets模块的用法实例
Sep 30 #Python
python根据路径导入模块的方法
Sep 30 #Python
python基于xml parse实现解析cdatasection数据
Sep 30 #Python
python中ConfigParse模块的用法
Sep 29 #Python
You might like
1.PHP简介
2006/10/09 PHP
PR值查询 | PageRank 查询
2006/12/20 PHP
解决PHP在DOS命令行下却无法链接MySQL的技术笔记
2010/12/29 PHP
PHP学习之数组的定义和填充
2011/04/17 PHP
解析thinkphp import 文件内容变量失效的问题
2013/06/20 PHP
PHP验证信用卡卡号是否正确函数
2015/05/27 PHP
详解EventDispatcher事件分发组件
2016/12/25 PHP
使用laravel指定日志文件记录任意日志
2019/10/17 PHP
JavaScript的类型简单说明
2010/09/03 Javascript
(jQuery,mootools,dojo)使用适合自己的编程别名命名
2010/09/14 Javascript
js新闻滚动 js如何实现新闻滚动效果
2013/01/07 Javascript
JSON格式化输出
2014/11/10 Javascript
JavaScript获得表单target属性的方法
2015/04/02 Javascript
Vue.js父与子组件之间传参示例
2017/02/28 Javascript
seajs实现强制刷新本地缓存的方法分析
2017/10/16 Javascript
JavaScript类数组对象转换为数组对象的方法实例分析
2018/07/24 Javascript
vue侧边栏动态生成下级菜单的方法
2018/09/07 Javascript
Vue中全局变量的定义和使用
2019/06/05 Javascript
JS 获取文件后缀,判断文件类型(比如是否为图片格式)
2020/05/09 Javascript
[03:09]2014DOTA2国际邀请赛 赛场上的美丽风景线 中国Coser也爱DOTA2
2014/07/20 DOTA
Python中encode()方法的使用简介
2015/05/18 Python
python 设置文件编码格式的实现方法
2017/12/21 Python
Python单元测试实例详解
2018/05/25 Python
python 定时任务去检测服务器端口是否通的实例
2019/01/26 Python
Python进阶之迭代器与迭代器切片教程
2020/01/29 Python
Python连接Oracle之环境配置、实例代码及报错解决方法详解
2020/02/11 Python
美国潜水装备、水肺潜水和浮潜设备商店:Leisure Pro
2018/08/08 全球购物
班级安全教育实施方案
2014/02/23 职场文书
化妆品促销方案
2014/02/24 职场文书
精彩广告词大全
2014/03/19 职场文书
文秘求职信范文
2014/04/10 职场文书
《夕阳真美》教学反思
2014/04/27 职场文书
餐饮周年庆活动方案
2014/08/14 职场文书
小爸爸观后感
2015/06/15 职场文书
资深HR教你写好简历中的自我评价
2019/05/07 职场文书
Matlab如何实现矩阵复制扩充
2021/06/02 Python