Python爬取网易云音乐热歌榜歌曲,并下载到本地
找到要下载歌曲排行榜的链接,这里用的是:
https://music.163.com/discover/toplist?id=3778678
#网易云热歌榜url
注意:1.然后更改你要保存的目录,目录要先建立好文件夹,就可以完成下载。如果文件夹没有提前建 好,会报错[Errno 2] No such file or directory。
2.直接copy是会报错TabError: inconsistent use of tabs and spaces in indentation
这是空格未对其问题(line41)
from urllib import request
from bs4 import BeautifulSoup
import re
import requests
import time
class Music(object):
def __init__(self, baseurl, path):
head = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
}
self.baseurl = baseurl
self.headers = head
self.path = path
def main(self):
html = self.askurl()
bs4 = self.analysis(html)
name1 = self.matching(bs4)
self