Python爬取网易云歌手信息

这个同样是作业…

早写完了,鸽了好久才发出来…

首先是根据指定歌手id获取歌手名和简介

import requests
import re
def spider(id):
    url="https://music.163.com/m/artist?id="+id
    headers={"user-agent": "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"}
    response=requests.get(url,headers=headers)
    response=response.text
    singer=re.findall(r'<meta name="keywords" content="(.*?)" />',response)
    introduce=re.findall('"briefDesc":"(.*?)"',response)
    result=dict(zip(singer,introduce))
    print(result)
id=input('请输入歌手id:\n')
spider(id)

我发现移动版的网易云更好搞,不需要cookie啥的,只要有个UA就能获取成功…

然后稍微处理一下就能取得信息了…

然后是获取所有亚洲男歌手id和姓名

import requests
import re
def spider(id):
    url="https://music.162.com/discover/artist/cat?id=1001&initial="+str(id)
    headers={"user-agent": "Mozilla/4.0 (Windows NT 10.0; Win64; x64; Cortana 1.11.6.17763; 10.0.0.0.17763.805) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"}
    response=requests.get(url,headers=headers)
    response=response.text
    singer=re.findall(r'<a href="/artist\?id=(.*?)" class="nm nm-icn f-thide s-fc-1" title="(.*?)的音乐"',response)
    singer=dict(singer)
    return singer
list={64,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,0}
singers=spider(-2)
for id in list:
    singers=dict(singers,**spider(id))
print(singers)

这个也很简单…UA用的Cortana的…虽然不知道有什么用…

就这样吧,这次的没什么难度

发表评论