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计数排序和基数排序算法实例
Apr 25 Python
Python字符串匹配算法KMP实例
Jul 18 Python
在Django的通用视图中处理Context的方法
Jul 21 Python
Python实现视频下载功能
Mar 14 Python
Pycharm更换python解释器的方法
Oct 29 Python
对python中类的继承与方法重写介绍
Jan 20 Python
Django项目使用CircleCI的方法示例
Jul 14 Python
python爬取Ajax动态加载网页过程解析
Sep 05 Python
python找出列表中大于某个阈值的数据段示例
Nov 24 Python
python破解同事的压缩包密码
Oct 14 Python
Python 3.9的到来到底是意味着什么
Oct 14 Python
python的dict判断key是否存在的方法
Dec 09 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
分享下php5类中三种数据类型的区别
2015/01/26 PHP
使两个iframe的高度与内容自适应,且相等
2006/11/20 Javascript
jQuery中文入门指南,翻译加实例,jQuery的起点教程
2007/02/09 Javascript
js中判断文本框是否为空的两种方法
2011/07/31 Javascript
javascript中取前n天日期的两种方法分享
2014/01/26 Javascript
JavaScript实现大数的运算
2014/11/24 Javascript
实现无刷新联动例子汇总
2015/05/20 Javascript
jQuery javascript获得网页的高度与宽度的实现代码
2016/04/26 Javascript
JSON对象 详解及实例代码
2016/10/18 Javascript
在node中如何使用 ES6
2017/04/22 Javascript
关于vue.js发布后路径引用的问题解决
2017/08/15 Javascript
vue-router中scrollBehavior的巧妙用法
2018/07/09 Javascript
vue2.0页面前进刷新回退不刷新的实现方法
2018/07/31 Javascript
vue 实现小程序或商品秒杀倒计时
2019/04/14 Javascript
微信小程序-form表单提交代码实例
2019/04/29 Javascript
JavaScript表格隔行变色和Tab标签页特效示例【附jQuery版】
2019/07/11 jQuery
vue keep-alive 动态删除组件缓存的例子
2019/11/04 Javascript
vuex入门最详细整理
2020/03/04 Javascript
[58:58]2018DOTA2亚洲邀请赛 4.4 淘汰赛 TNC vs VG 第二场
2018/04/05 DOTA
Python实现MySQL操作的方法小结【安装,连接,增删改查等】
2017/07/12 Python
理论讲解python多进程并发编程
2018/02/09 Python
Python列表list排列组合操作示例
2018/12/18 Python
python 函数内部修改外部变量的方法
2018/12/18 Python
基于wxPython的GUI实现输入对话框(2)
2019/02/27 Python
python实现微信机器人: 登录微信、消息接收、自动回复功能
2019/04/29 Python
pygame实现俄罗斯方块游戏(AI篇2)
2019/10/29 Python
python lambda函数及三个常用的高阶函数
2020/02/05 Python
pytorch 移动端部署之helloworld的使用
2020/10/30 Python
HTML4和HTML5之间除了相似以外的10个主要不同
2012/12/13 HTML / CSS
JAVA和C++的区别
2013/10/06 面试题
写给老婆的检讨书
2014/02/21 职场文书
不遵守课堂纪律的检讨书
2014/09/24 职场文书
2015年第十五个全民国防教育日宣传活动方案
2015/05/06 职场文书
新员工实习期个人工作总结
2015/10/15 职场文书
小学运动会开幕词
2016/03/04 职场文书
Python进程间的通信之语法学习
2022/04/11 Python