发布于 2015-03-19 10:54:46 | 177 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Python教程,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


Python下载网易云音乐的高清MV,没有从首页进去解析,直接循环了....

downPage1.py

 
#coding=utf-8
import urllib
import re
import os
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
def getVideo(html):
    reg = r'hurl=(.+?.jpg)'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    return imglist
for num in range(28000,1000000):
    print num
    html = getHtml("http://music.163.com/mv?id=%s"%num)
    parsed = getVideo(html)
    if  len(parsed)==0:
        continue
    vedioUrls = parsed[0].split("&")
    artist = vedioUrls[4].split("=")[1].decode('utf-8').strip()
    song = vedioUrls[3].split("=")[1].decode('utf-8').strip()
    if  len(vedioUrls[0])==0:
        continue
    filename = '%s/%s.mp4' %(artist,song)
    if "/" in song:
        continue
    if os.path.exists(filename):
        print 'the MV file exists.%s'%num
    else:
        print 'the MV is downloding.%s'%num
        if  os.path.exists(artist):
            print ""
        else:
            os.makedirs(artist)
        urllib.urlretrieve(vedioUrls[0],filename)


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务