• 大小: 4.43KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-03-01
  • 语言: Python
  • 标签: 爬虫  音乐  实例  

资源简介

用于网易云音乐中的音乐爬取并下载,而且可爬取到云热评

资源截图

代码片段和文件信息

import requests
import json
from bs4 import BeautifulSoup#定位数据
import time
import os#保存文件时候用到

class hotComments:
    def __init__(self):
        self.headers = {
            “User-Agent“: “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/73.0.3683.86 Safari/537.36“
        }
    #offset页数limit一页显示最多的评论数
    def get_hotComments(selfmusic_id):
        self.url = “http://music.163.com/api/v1/resource/comments/R_SO_4_{}?offset=0&limit=50“.format(music_id)
        try:
            self.text = json.loads(requests.get(self.url headers=self.headers).text)
            datas = self.text[‘hotComments‘]
        except:
            print(“没有找到该歌曲的热评“)
            return
        print(“\n\n\n“+“网易云热评:   “+“--------“*20+“\n\n\n“)
        for content in datas:
            print(content[‘content‘])
        print(“\n\n\n“+“---分--界--线----“*20)
 
    def get_music_id(self urls=None):
        #用到异常处理机制
        try:
            html = requests.g

评论

共有 条评论