import requests
from bs4 import BeautifulSoup
import json
import xlwt
#存储成Excel表格的函数
def save_excel(comment,save_file):
#第一个参数的整个评论存储所在的列表
wb=xlwt.Workbook()
sheet=wb.add_sheet('评论')
for i in range(len(comment)): #第i个评论列表
for j in range(len(comment[i])):
sheet.write(i,j,comment[i][j])
wb.save('C:/Users/Xpeng/Desktop/爬取到的表格/'+save_file)
#----爬取QQ音乐某首歌(topid区分)的评论
def song_comment(topid):
url='https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg'
comment_id=''
all_com=[]
for p in range(10):
params={
'g_tk':'5381',
'loginUin':'943413047',
'hostUin': '0',
'format': 'json',
'inCharset': 'utf8',
'outCharset':'GB2312',
'notice':'0',
'platform':'yqq.json',
'needNewCode':'0',
'cid':&#
练习---爬取QQ音乐某首歌的评论,并存入Excel表中---以《消愁》为例
最新推荐文章于 2024-03-26 21:25:51 发布
本文介绍如何使用Python爬虫获取QQ音乐《消愁》这首歌的用户评论,并将数据整理存储到Excel表格中,涉及requests、BeautifulSoup和pandas库的使用。
摘要由CSDN通过智能技术生成