网易云网站直接打开源代码里面并没有对应的歌曲信息,需要对url做处理,
查看网站源代码路径;发现把里面的#号去掉会显示所有内容,
右键打开的源代码路径:view-source:https://music.163.com/#/discover/toplist?id=3778678
去掉#号后:view-source:https://music.163.com/discover/toplist?id=3778678
资源拿到了,开始写代码;
如果你对python感兴趣,我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:688244617
import requests
from lxml import etree
import os
from multiprocessing import Pool
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
# 创建存储路径
pathname = './music/'
if not os.path.exists(pathname):
os.mkdir(pathname)
# 获取歌曲链接的函数
def get_urls(url):
try:
response = requests.get(url=url,headers=headers)
music