Python 爬取QQ音乐个人单曲排行榜

本文介绍了如何利用Python分析网页结构,通过XHR请求获取QQ音乐个人单曲排行榜的数据。具体步骤包括识别xhr中的歌曲信息,并展示了相关代码实现。
摘要由CSDN通过智能技术生成
  • 分析网页成分,歌曲信息都存在图中所示xhr中

  •  详细代码实现如下:
import os
import threading
import jieba
import numpy
import html
import requests
import openpyxl
from wordcloud import WordCloud
import PIL.Image as Image


# 设置最大线程锁
thread_lock = threading.BoundedSemaphore(value=10)

# 全局域名地址,用于拼接网址
domain_url = 'https://y.qq.com/n/yqq/song/'

HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/80.0.3987.162 Safari/537.36 Edg/80.0.361.109',
    'Referer': 'https://y.qq.com/n/yqq/song/0039MnYb0qxYhV.html'
}

# 创建工作簿
wb = openpyxl.Workbook()
# 获取工作簿的活动表
sheet = wb.active
# 工作表重命名
sheet.title = 'song'

# 加表头,分别给A1B1C1单元格赋值
sheet['A1'] = '歌曲名'
sheet['B1'] = '所属专辑'
sheet['C1'] = '播放链接'


# 判断是否有文件夹,无则创建
if not os.path.exists('H:\PythonWorks\QQmusic\评论'):
    os.makedirs('H:\PythonWorks\QQmusic\评论')
    COMMENT_PATH = 'H:\PythonWorks\QQmusic\评论'
if not os.path.exists("H:\PythonWorks\QQmusic\歌词"):
    os.makedirs("H:\PythonWorks\QQmusic\歌词")
    LYRIC_PATH = "H:\PythonWorks\QQmusic\歌词"
if not os.path.exists('H:\PythonWorks\QQmusic\热评'):
    os.makedirs('H:\PythonWorks\QQmusic\热评')
    HOT_COMMENT_PATH = 'H:\PythonWorks\QQmusic\热评'
if not os.path.exists('H:\PythonWorks\QQmusic\词云'):
    os.makedirs('H:\PythonWorks\QQmusic\词云')
    CIYUN_PATH = 'H:\PythonWorks\QQmusic\词云'


def cut(text):
    wordlist_jieba = jieba.cut(text)
    space_wordlist = " ".join(wordlist_jieba)
    return space_wordlist


# 生成热评词云
def ciyun(path_name, music_name):
    with open(path_name, encoding='utf-8') as f:
   
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值