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

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

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

相关文章

将TensorFlow的模型网络导出为单个文件的方法

有时候,我们需要将TensorFlow的模型导出为单个文件(同时包含模型架构定义与权重),方便在其他地方使用(如在c++中部署网络)。利用tf.train.write_graph()默认...

使用Python制作微信跳一跳辅助

使用Python制作微信跳一跳辅助

1.  前言 微信的跳一跳相信大家都很熟悉了,而且现在各种外挂、辅助也是满天飞,反正本人的好友排行榜中已经是八九百都不足为奇了。某宝上一搜一堆结果,最低的居然只要3块多,想刷多...

python登录豆瓣并发帖的方法

本文实例讲述了python登录豆瓣并发帖的方法。分享给大家供大家参考。具体如下: 这里涉及urllib、urllib2及cookielib常用方法的使用 登录豆瓣,由于有验证码,采取的办...

Python操作MySQL数据库9个实用实例

Python操作MySQL数据库9个实用实例

在Windows平台上安装mysql模块用于Python开发 用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示。下边是打包了32与64版本。 MySQL-py...

Python实用库 PrettyTable 学习笔记

本文实例讲述了Python实用库 PrettyTable。分享给大家供大家参考,具体如下: PrettyTable安装 使用pip即可十分方便的安装PrettyTable,如下: p...