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: