使用Python实现下载网易云音乐的高清MV

yipeiwu_com5年前Python基础

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)

以上就是本文分享的全部代码了,希望大家能够喜欢。

相关文章

Python分支语句与循环语句应用实例分析

本文实例讲述了Python分支语句与循环语句应用。分享给大家供大家参考,具体如下: 一、分支语句 1、if else语句 语法: if 条件判断: 执行的语句块1 else :...

Python简单计算给定某一年的某一天是星期几示例

Python简单计算给定某一年的某一天是星期几示例

本文实例讲述了Python简单计算给定某一年的某一天是星期几。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- #计算某特定天使星期几 #蔡勒公式:w=...

pytorch自定义初始化权重的方法

在常见的pytorch代码中,我们见到的初始化方式都是调用init类对每层所有参数进行初始化。但是,有时我们有些特殊需求,比如用某一层的权重取优化其它层,或者手动指定某些权重的初始值。...

介绍Python的Urllib库的一些高级用法

介绍Python的Urllib库的一些高级用法

1.设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Headers 的属性。 首先,...

python 布尔操作实现代码

和别的语言布尔类型定义1为真,0为假不同,python定义的真假比较多。 先说下假吧: false,none,0,"",{},[],() 而真的话,只要和上面的相反就行,比如上面是fal...