使用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)

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

相关文章

解决django-xadmin列表页filter关联对象搜索问题

环境:xadmin-for-python3 python3.5.2 django1.9.12 问题描述:Product ProductSku两个实体,ProductSku FK外键关联P...

python隐藏类中属性的3种实现方法

python隐藏类中属性的3种实现方法

方法一: 效果图一: 代码一: # 定义一个矩形的类 class Rectangle: # 定义初始化方法 def __init__(self,width,height):...

跟老齐学Python之传说中的函数编写条规

关于函数的事情,总是说不完的,下面就罗列一些编写函数的注意事项。特别声明,这些事项不是我总结的,我是从一本名字为《Learning Python》的书里面抄过来的,顺便写成了汉语,当然,...

Python下利用BeautifulSoup解析HTML的实现

摘要 Beautiful Soup 是一个可以从 HTML 或 XML 格式文件中提取数据的 Python 库,他可以将HTML 或 XML 数据解析为Python 对象,以方便通过P...

11个Python Pandas小技巧让你的工作更高效(附代码实例)

本文为你介绍Pandas隐藏的炫酷小技巧,我相信这些会对你有所帮助。 或许本文中的某些命令你早已知晓,只是没意识到它还有这种打开方式。 Pandas是一个在Python中广泛应用的数据...