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

yipeiwu_com6年前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)

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

相关文章

在Python3 numpy中mean和average的区别详解

mean和average都是计算均值的函数,在不指定权重的时候average和mean是一样的。指定权重后,average可以计算一维的加权平均值。 具体如下: import num...

用python wxpy管理微信公众号并利用微信获取自己的开源数据

用python wxpy管理微信公众号并利用微信获取自己的开源数据

之前了解到itchat 乃至于 wxpy时 是利用tuling聊天机器人的接口。调用接口并保存双方的问答结果可以作为自己的问答词库的一个数据库累计。这些数据可以用于自己训练。 而最近希望...

Anaconda2 5.2.0安装使用图文教程

Anaconda2 5.2.0安装使用图文教程

Anacond的介绍 Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项。 因为包含了大量的科学包,Anacon...

解决安装pyqt5之后无法打开spyder的问题

解决安装pyqt5之后无法打开spyder的问题

运行某demo时候按照提示安装了pyqt5,然后通过命令行去打开spyder时就报这个错: 错误的说法分别有: 1、anaconda里面已经装了pyqt5,在通过pip install...

python将list转为matrix的方法

如下所示: import numpy as np tmp = [[1,2,3],[4,5,6],[7,8,9]]; np.matrix(tmp) 以上这篇python将list转...