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存储16bit和32bit图像的实例
Dec 05 Python
django开发post接口简单案例,获取参数值的方法
Dec 11 Python
使用Python的OpenCV模块识别滑动验证码的缺口(推荐)
May 10 Python
python 基于TCP协议的套接字编程详解
Jun 29 Python
Django admin禁用编辑链接和添加删除操作详解
Nov 15 Python
python构建指数平滑预测模型示例
Nov 21 Python
使用jupyter notebook将文件保存为Markdown,HTML等文件格式
Apr 14 Python
解决python3.6用cx_Oracle库连接Oracle的问题
Dec 07 Python
浅析pandas随机排列与随机抽样
Jan 22 Python
Python+Appium实现自动化清理微信僵尸好友的方法
Feb 04 Python
python通配符之glob模块的使用详解
Apr 24 Python
Python基础之进程详解
May 21 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
Laravel5.1框架路由分组用法实例分析
2020/01/04 PHP
Prototype Hash对象 学习
2009/07/19 Javascript
javascript 不间断的图片滚动并可点击
2010/01/15 Javascript
js中判断控件是否存在
2010/08/25 Javascript
使用jQuery模板来展现json数据的代码
2010/10/22 Javascript
js确定对象类型方法
2012/03/30 Javascript
jquery 滚动条事件简单实例
2013/07/12 Javascript
JavaScript中window、doucment、body的解释
2013/08/14 Javascript
js获取下拉列表的值和元素个数示例
2014/05/07 Javascript
node.js中的fs.rmdirSync方法使用说明
2014/12/16 Javascript
jQuery简单实现仿京东分类导航层效果
2016/06/07 Javascript
JS实现动态表格的添加,修改,删除功能(推荐)
2016/06/15 Javascript
js时间控件只显示年月
2017/01/08 Javascript
JavaScript基于Dom操作实现查找、修改HTML元素的内容及属性的方法
2017/01/20 Javascript
jquery滚动条插件slimScroll使用方法
2017/02/09 Javascript
详解React 16 中的异常处理
2017/07/28 Javascript
mescroll.js上拉加载下拉刷新组件使用详解
2017/11/13 Javascript
解决vue中修改export default中脚本报一大堆错的问题
2018/08/27 Javascript
基于Vue插入视频的2种方法小结
2019/04/02 Javascript
使用flow来规范javascript的变量类型
2019/09/12 Javascript
vue实现在线预览pdf文件和下载(pdf.js)
2019/11/26 Javascript
[原创]使用豆瓣提供的国内pypi源
2017/07/02 Python
Python实现读取Properties配置文件的方法
2018/03/29 Python
Django如何将URL映射到视图
2019/07/29 Python
pytorch 求网络模型参数实例
2019/12/30 Python
css3使用animation属性实现炫酷效果(推荐)
2020/02/04 HTML / CSS
html5弹跳球示例代码
2013/07/23 HTML / CSS
历史系自荐信范文
2013/12/24 职场文书
党员岗位承诺口号大全
2014/03/28 职场文书
《冬阳童年骆驼队》教学反思
2014/04/15 职场文书
乔丹名人堂演讲稿
2014/05/24 职场文书
大学生求职信
2014/06/17 职场文书
再婚婚前财产协议书范本
2014/10/19 职场文书
后进生评语大全
2015/01/04 职场文书
7个关于Python的经典基础案例
2021/11/07 Python
python获取带有返回值的多线程
2022/05/02 Python